Problem with C# project analysis

Hello there, i am analyzing a simple c# project, The analysis is running successfully and the data is passed to sonarcloud. But i do not see any measures (lines of code, cyclomatic complexity,…) and do not know what config i missed or what else i can do wrong…

I am working with the ‘dotnet tool install --global dotnet-sonarscanner’ tool and executing the sonar analysis with the following 4 command:

dotnet sonarscanner begin /"$SONAR_HOST" /d:sonar.sources="$SOURCES" /d:sonar.login="$SONAR_LOGIN_KEY" /k:"$PROJECT_KEY" /o:"$SONAR_ORGANIZATION"
dotnet restore
dotnet build
dotnet sonarscanner end /d:sonar.login="$SONAR_LOGIN_KEY"

I really look forward for your help, because i do not know where to look for a solution for this problem. Does not find any other documented issues like that, except this one:

But my project does not contain a Test/test in name and to be sure i used the current parameter sonar.msbuild.testProjectPattern to ensure that the project is NOT analysed as a test project.

hi @Jakob_Blume1 and welcome to the community !

The Scanner for MSBuild embed its own engine to detect all the source file that it should analyze.

So first thing first, i would suggest to try to invoke the begin step without the sonar.sources and let us know how it goes.

Thank you !


Hi and thank you for the warm welcome :slight_smile:

This is what i already tried :frowning: This sadly does not change the result.

Ok, so then could you please send me the logs of the step 'dotnet sonarscanner end /d:sonar.login="$SONAR_LOGIN_KEY", in debug mode ? You can enable it by adding the /d:sonar.verbose=true

With redacted stuff if needed, or i can send it to me via PM, just let me know.

Thank you.

1 Like

Hi, i has to add the /d:sonar.verbose=true to the begin call, but now i got the following debug output:
log.txt (50.5 KB)

Thank you !

So, as far as i can see, no source are detected, and only 2 files are categorized as tests :


Do you have any other source file in your project / solution ?

Otherwise, if you want the scanner to not detect those files as test, you can add the following property group in your csproj :

	<!-- Mark the project as being a test project -->
1 Like

Thank you, that was the fix!! :slight_smile: I was searching in the right direction, but does not know about the PropertyGroup setting. One further question: Is there a way to disable the Check for TestProject in the CLI call and not with editing the project settings?

In fact this check and more globally the target that is executed is lead by the Scanner for MSBuild itself, and here are the rules :

  • Projects whose full project file name matches the regular expression specified in
    the analysis setting “sonar.msbuild.testProjectPattern” will be treated as test
    projects. This setting is set via the SonarQube portal (set “Test project pattern”
    in the per-project settings on the MSBuild tab for the C# plug-in).
    By deault, any projects with “test” (case-insensitive) in the project name will
    be treated as test projects.
    Note that the regular expression uses the .Net Regex format i.e. “+” is the
    single character wildcard and “*” is the multi-character wildcard (zero to many).
  • MSTest projects will be treated as test projects.
    The $(ProjectTypeGuids) property of MS Test projects contains a specific guid

There’s no way to disable this check specifically for the moment.


1 Like

Thank you for the information and your help!

And one other tip : i think that the best practice would be to separate your source code and unit tests in separate projects (one with the UT will be categorized as Test project, and the other one will be analyzed), so it should be easier for you to manage.

Yeah, you are right :+1: