You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[generator-Tests] Use Roslyn for .NET Core Support (dotnet#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/
0 commit comments