Emit a warning when insufficient compiler version is used with the SDK
See original GitHub issueIs your feature request related to a problem? Please describe.
Recently we were debugging a failing issue which a scenario using Microsoft extensions logging source generator which requires C# compiler 4.4
. The user was using 2022 VS v17.3.6
which using C# compiler 4.3.0-3.22470.13 (80a8ce8d)
. The source generation in the project will fail to work and will end up with a compiler error like: C:\scratch\webApp\Program.cs(35,32): error CS8795: Partial method 'Log.Hello(ILogger, string)' must have an implementation part because it has accessibility modifiers. [C:\scratch\webApp\webApp.csproj]
which gives a hint there is a source generation problem but not clear what exactly the problem is especially compiling the same project on another machine happens to use compiler version 4.4
make it succeed.
Note, the project we were debugging was disabling the warning CS9057
which was hiding more information about the failure. Had they not disabled this warning they would have seen numerous warnings:
CSC : warning CS9057: The analyzer assembly 'C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\7.0.2\analyzers\dotnet\cs\Microsoft.Interop.JavaScript.JSImportGenerator.dll' references version '4.4.0.0' of the compiler, which is newer than the currently running version '4.3.0.0'.
CSC : warning CS9057: The analyzer assembly 'C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\7.0.2\analyzers\dotnet\cs\Microsoft.Interop.LibraryImportGenerator.dll' references version '4.4.0.0' of the compiler, which is newer than the currently running version '4.3.0.0'.
CSC : warning CS9057: The analyzer assembly 'C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\7.0.2\analyzers\dotnet\cs\System.Text.Json.SourceGeneration.dll' references version '4.4.0.0' of the compiler, which is newer than the currently running version '4.3.0.0'.
CSC : warning CS9057: The analyzer assembly 'C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\7.0.2\analyzers\dotnet\cs\System.Text.RegularExpressions.Generator.dll' references version '4.4.0.0' of the compiler, which is newer than the currently running version '4.3.0.0'.
CSC : warning CS9057: The analyzer assembly 'C:\Program Files\dotnet\packs\Microsoft.AspNetCore.App.Ref\7.0.2\analyzers\dotnet\cs\Microsoft.AspNetCore.App.Analyzers.dll' references version '4.4.0.0' of the compiler, which is newer than the currently running version '4.3.0.0'.
CSC : warning CS9057: The analyzer assembly 'C:\Program Files\dotnet\packs\Microsoft.AspNetCore.App.Ref\7.0.2\analyzers\dotnet\roslyn4.4\cs\Microsoft.Extensions.Logging.Generators.dll' references version '4.4.0.0' of the compiler, which is newer than the currently running version '4.3.0.0'.
Describe the solution you’d like
When using SDK version (which allows source generation) with insufficient compiler version, should produce more logging to warn about the issue.
Additional context
This is easily can reproduce by creating a project and use the compiler version 4.3
and have some source generation code.
Issue Analytics
- State:
- Created 8 months ago
- Comments:6 (2 by maintainers)
Top GitHub Comments
@earloc that might be more related to https://github.com/dotnet/roslyn-sdk/issues/955 and https://github.com/dotnet/sdk/issues/20355.
@ericstj feel free to add/edit the issue if I didn’t capture anything.