[LoggerMessage] fail when build with sonarscanner

When using [LoggerMessage] and source generator for logs, sonar doesn’t find the generated code.
CS8795: Partial method '...' must have an implementation part because it has accessibility modifiers.

  • dotnet-sonarscanner 5.5.3
  • Sonar TargetFramework .net5.0

The same build without sonar on same agent is working.

@Andrei_Epure do you know if there is a fix for this?
I saw the issue C# Sonar Scanner with Source Generators that was fixed by updating sonarqube but we are using sonarcloud.

There is any sample where the Microsoft.Extensions.Logging.Generators is working?

Additional info:

  • project TargetFramework .NET 6

Thanks!

Hi,

Welcome to the community!

Please don’t @ people who aren’t already involved in your thread.

This topic is tagged to draw the correct attention, but community support is a sideline for most SonarSourcers, so it may take some time.

 
Thx,
Ann

@ganncamp already 14d and nobody is answering.

As an update there is a pretty complicated workaround by patching the SonarQubeAnalysisConfig.xml and add a new AnalyzerPlugin entry where I added a path to the Microsoft.Extensions.Logging.Generators.dll.

For the Razor I saw that there was a fix by adding the reference in the securitycsharpfrontend plugin. What about all other analyzers/sourcegenerators ? It should be a more flexible way of including the in the build process.

Hi @glucaci, sorry for taking so long to answer.

I suggest continuing the discussion on GitHub on the issue you added for this.

Update for other forum users: currently, if you want to use Roslyn source generators in your builds, don’t set sonar.cs.roslyn.ignoreIssues=true.

The default is false, so it will only be true if it has been explicitly modified (see the scanner docs for more info). The setting tells the SonarScanner for .NET to remove non-Sonar analyzers from the compilation. Unfortunately, Roslyn source generators are registered in the same way as analyzers, so they are removed from the build too. This issue is being tracked in S4NET-1211.

2 Likes