Replace System.CodeDom with Roslyn Microsoft.CodeAnalysis#5142
Replace System.CodeDom with Roslyn Microsoft.CodeAnalysis#5142OsirisTerje merged 8 commits intomainfrom
Conversation
Also reduce instantiation to one per fixture.
There was a problem hiding this comment.
Pull request overview
This pull request replaces System.CodeDom with Roslyn's Microsoft.CodeAnalysis for in-memory assembly compilation in tests, enabling cross-platform test execution. Previously, tests using System.CodeDom were restricted to .NET Framework only.
Changes:
- Introduced new
TestCompilerclass using Roslyn APIs for cross-platform compilation - Removed .NET Framework-specific conditional compilation directives from test files
- Updated package dependencies to include Microsoft.CodeAnalysis.CSharp 4.12.0
- Upgraded System.Collections.Immutable to 8.0.0 for compatibility
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/NUnitFramework/tests/nunit.framework.tests.csproj | Added Microsoft.CodeAnalysis.CSharp package reference |
| src/NUnitFramework/tests/TestUtilities/TestCompiler.cs | New cross-platform test compiler using Roslyn APIs |
| src/NUnitFramework/tests/TestUtilities/TestAssemblyHelper.cs | Removed old .NET Framework-only helper class |
| src/NUnitFramework/tests/Syntax/TestCompiler.cs | Removed old .NET Framework-only compiler class |
| src/NUnitFramework/tests/Syntax/InvalidCodeTests.cs | Migrated to use new TestCompiler, removed conditional compilation |
| src/NUnitFramework/tests/Attributes/LifeCycleAttributeTests.cs | Migrated to use new TestCompiler, removed conditional compilation for assembly-level tests |
| src/NUnitFramework/Directory.Packages.props | Added Roslyn package versions and upgraded System.Collections.Immutable |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Why do I even need to specify this manually.
|
@manfred-brands Thanks for looking into this. In the event that you're running into the same reference assembly issue I did, I was able to reproduce it locally outside of any build server by running |
|
I just noticed that myself. Maybe something related to how nunitlite runs tests |
Root cause: When tests are run via nunitlite-runner, it's the host process and its deps.json/config file is used for
PS: Needed some help from my friend Claude to find the issues though. :-) |
This is a downside that the runner needs to know all the dependencies of the assemblies it is testing. |
|
@manfred-brands Agree. Not sure what we, or if, we should do anything about it. |
|
From what I can recall the tests have historically used the console runner though that posed issues with cyclical dependencies, in particular with dependencies outside the framework even though the console runner is still within the Nunit umbrella. I wonder if this could be a use case for us to lean on Nunit Lite's "self executing test" feature if that shifts the entry point from the runner to the test assembly itself |
|
Right you are, so it doesn't do that now. I missed that detail. Assumptions...... |
Fixes #5131
Most work done by Copilot.