C# code not being analyze in VSTS pipeline

I’m using VSTS pipeline and Sonar C# 7.15 but my C# code is not getting analyzed. I found that it requires MSBuild version 14+ but where do I specify in VSTS pipeline.

If you click on the (!) next to Visual Studio Version in the Visual Studio build step you’ll see the following:

image

i.e. you specify a preference in the build step, but it depends what is installed on the build agent.
You shouldn’t set /p:VisualStudioVersion=xxx directly: that’s one of the variable set when you launch a Visual Studio Developer command prompt (along with a number of other related environment variables).

  • are you using a self-hosted build agent? If so, the version of MSBuild used will be the one you have installed on the build agent.
  • what warnings/errors are you seeing in the logs?

Attaching logs. I’m using latest visual studio version but still C# code is not being analysed. Could you please tell where is the isssue?8.txt (133.0 KB)

Hi,

You need to execute the MSBuild scanner in order to get your C# code analyzed (In the Prepare analysis on SonarQube task, you need to select “Integrate with MSBuild”). Otherwise you won’t. (in your case this is invoking the Scanner CLI itself)

Mickaël

I have done change per your suggestion ( was doing same earlier) but this time it doesn’t show anything. 7.txt (1.1 MB)

any reply you would like to give?

Can you please share both Prepapre analysis and Run Code Analysis logs in debug mode ? So that we can have a look.

Thank you.

Hi Mickaël,
6.txt (1.8 KB) 8.txt (10.9 KB)

Attached are two logs.

I think that the /p:OutDir is kind of interfering with the detection of the files to be analyzed, because it shows at 0 in the logs.

Could you try removing this option in the MSBuild params and try again ?

Thanks.

Still it shows same error.

Can you share the Run Code analysis with system.debug=true ? The one you gave doesn’t have the debug enabled.

Thanks in advance.

10.txt (2.1 MB) Logs with debugging details.

All your sources are classified as test by the Scanner. Please check whether the csproj is in one or the other assumption here :

1) 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 default, 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).

2) MSTest projects will be treated as test projects.
    The $(ProjectTypeGuids) property of MS Test projects contains a specific guid
    ("3AC096D0-A1C2-E12C-1390-A8335801FDAB")

Where do I see sonar.msbuild.testProjectPattern properties in SonarQube Community portal 7.9.1. For me it shows below

It’s not settable through the UI, only passed through the analyzer.

Did you set somehow the project as a Unit Test project, or changed it from Unit Test to something else ?

I suggest that you check it’s GUID, either in the solution, or in the csproj itself, it it’s a .NET framework one.

I see below details in .csproj

ProjectGuid ==> {859452A3-7951-4AEA-A8AC-B6FF0ED01342}
ProjectTypeGuids=> {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}

Ok, that not looks at a test project guid.

Can you share the build output log, in debug mode as well ? So i’ll get the debug message that we have in our targets.

Thanks.

Below are the buid log files with debug information (splitted into three because of size issue)
9_1.txt (2.7 MB) 9_2.txt (2.5 MB) 9_3.txt (3.1 MB)

Given the logs, we are detecting an old Service tag, which has certainly been added by the Test explorer window while running some unit tests on your project.

It should look like this :

<ItemGroup>
  <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>

Either remove it (if your project is not at all a unit test project), or split the unit tests into a different project, so this behavior will not occur anymore.

Mickaël

Hi Mickaël,

It got worked. Could you please tell me

  1. How do I identify if service tag is been added because of test project?
  2. How I can still force sonarqube to consider project as non-test project even this tag is been added.
  3. Can I use sonar-project.properties through VSTS pipeline to scan specific modules only. If not then how do I make such selection?
  4. Earlier you said I need to execute the MSBuild scanner in order to get C# code analyzed (In the Prepare analysis on SonarQube task, you need to select “Integrate with MSBuild”). If this option I select, it won’t allow me to use sonar-project.properties.
  5. Sonarqube community edition doesn’t executes VSTS pipeline on cloned branch (non-master branch). Is this true?