When customers build with msbuild they get the compiler that comes with the Visual Studio but many of the tasks and targets that ship with the chosen .NET SDK. Practically speaking that means analyzers / generators come from the .NET SDK install but the compiler that runs them comes from Visual Studio.
This can lead to problems when the version of .NET SDK is newer than MSBuild. That opens up the potential for analyzers / generators to exist that depend on a newer version of the Roslyn compiler than exists in MSBuild. When that happens customers will get errors like the following:
CSC : warning CS9057: The analyzer assembly '..\dotnet\sdk\8.0.200\Sdks\Microsoft.NET.Sdk.Razor\source-
generators\Microsoft.CodeAnalysis.Razor.Compiler.SourceGenerators.dll' references version '4.9.0.0' of the compiler, which is newer
than the currently running version '4.8.0.0'.
To fix this issue we're going to change the workflow here such that MSBuild will use the same compiler as the .NET SDK when the .NET SDK is newer than the running MSBuild. There are several pieces involved in getting this working:
[x] Roslyn will produce a NuPkg that overrides the compiler in MSBuild (#66206)
[x] MSBuild will make a change such that BuildWithNetFrameworkHostedCompiler is true whenever it detects a MSBuild / .NET SDK mismatch. (https://github.com/dotnet/sdk/pull/39701)
[ ] dotnet build-server shutdown will update such that it can shut down compilers from this NuPkg.
[ ] Update our test passes to include validating these scenarios are working
[ ] Change arcade to have BuildWithNetFrameworkHostedCompiler set to true by default.
Note: in this issue the term msbuild or MSBuild refers to the .NET Framework MSBuild installed with Visual Studio, notdotnet msbuild.
When customers build with
msbuild
they get the compiler that comes with the Visual Studio but many of the tasks and targets that ship with the chosen .NET SDK. Practically speaking that means analyzers / generators come from the .NET SDK install but the compiler that runs them comes from Visual Studio.This can lead to problems when the version of .NET SDK is newer than MSBuild. That opens up the potential for analyzers / generators to exist that depend on a newer version of the Roslyn compiler than exists in MSBuild. When that happens customers will get errors like the following:
To fix this issue we're going to change the workflow here such that MSBuild will use the same compiler as the .NET SDK when the .NET SDK is newer than the running MSBuild. There are several pieces involved in getting this working:
BuildWithNetFrameworkHostedCompiler
that installs this NuPkg (https://github.com/dotnet/sdk/pull/32734)BuildWithNetFrameworkHostedCompiler
is true whenever it detects a MSBuild / .NET SDK mismatch. (https://github.com/dotnet/sdk/pull/39701)dotnet build-server shutdown
will update such that it can shut down compilers from this NuPkg.BuildWithNetFrameworkHostedCompiler
set totrue
by default.Note: in this issue the term
msbuild
or MSBuild refers to the .NET Framework MSBuild installed with Visual Studio, notdotnet msbuild
.