Skip to content

Analyzer tearing issues with MSBuild and .NET SDK disagree on compilers #72672

@jaredpar

Description

@jaredpar

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:

Note: in this issue the term msbuild or MSBuild refers to the .NET Framework MSBuild installed with Visual Studio, not dotnet msbuild.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions