-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[generator-Tests] Use Roslyn for .NET Core Support (#638)
How do we test the C# output of `generator`? *A* way is to check the output against "known good" files, which we do. *Another* way is to use a compiler to ensure that the output compiles, which we *also* do. Unfortunately, the "just compile it!" approach has a major flaw, as the easiest accessible C# compiler is `Microsoft.CSharp.CSharpCodeProvider`, for use with System.CodeDom, but *on Windows* `CSharpCodeProvider` only supports up to C# 5. `generator`, meanwhile, may currently produce C# 8 output. This conundrum was addressed in commit 968b474 by using the [Microsoft.CodeDom.Providers.DotNetCompilerPlatform][0] NuGet package when running on Windows, as that supported C#6+. Unfortunately, `DotNetCompilerPlatform` does *not* run under .NET Core, because it uses the MSBuild `CodeTaskFactory` which is not available on .NET Core. ([This issue has been fixed][1]; the fix is unreleased.) Now that we support multitargeting net471 and netcoreapp3.1 (95f698b), we would like to be able to build *and run* our unit tests under .NET Core as well as Mono (macOS) or .NET Framework (Windows). Migrate away from the `DotNetCompilerPlatform` NuGet package and instead use the [Microsoft.CodeAnalysis.CSharp][2] NuGet package, which contains an up-to-date C#8 Roslyn compiler. This new package supports .NET Core; we just need to update `Compiler.Compile()` to work in terms of Roslyn SyntaxTrees instead of CodeDom objects. This allows us to run the `generator` unit tests under .NET Core: dotnet test bin\TestDebug\generator-tests.dll [0]: https://www.nuget.org/packages/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/ [1]: aspnet/RoslynCodeDomProvider#51 [2]: https://www.nuget.org/packages/Microsoft.CodeAnalysis.CSharp/
- Loading branch information
Showing
2 changed files
with
63 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters