Build failed for c# projects

Hi, I’m tring to scan c# projects but get build failed every time.

I’m using sonarqube version and sonarscanner for msbuild version

the project i’m tring to scan is mono-master that availble to download here:

The full log is attached.

mono log.txt (345.0 KB)

Thank you!

Hi @Erez_Dasa,

The log is full of MSBuild errors that are nothing to do with SonarQube e.g.

  Creating directory "./../../class/obj/mscorlib-net_4_x-win32\".
Project "C:\temp\csahrp\mono-master\mono-master\mcs\class\corlib\corlib.csproj" (5) is building "C:\temp\csahrp\mono-ma
ster\mono-master\mcs\tools\cil-stringreplacer\cil-stringreplacer.csproj" (4:2) on node 1 (Clean target(s)).
C:\temp\csahrp\mono-master\mono-master\mcs\tools\cil-stringreplacer\cil-stringreplacer.csproj(38,44): error MSB4066: Th
e attribute "Version" in element <PackageReference> is unrecognized.
Done Building Project "C:\temp\csahrp\mono-master\mono-master\mcs\tools\cil-stringreplacer\cil-stringreplacer.csproj" (
Clean target(s)) -- FAILED.

Done Building Project "C:\temp\csahrp\mono-master\mono-master\mcs\class\corlib\corlib.csproj" (Rebuild target(s)) -- FAILED.


Project "C:\temp\csahrp\mono-master\mono-master\bcl.sln" (1) is building "C:\temp\csahrp\mono-master\mono-master\mcs\cl
ass\System\System.csproj" (7) on node 1 (Rebuild target(s)).
  Creating directory "./../../class/obj/System-net_4_x-win32\".
Done Building Project "C:\temp\csahrp\mono-master\mono-master\mcs\class\System\System.csproj" (Rebuild target(s)) -- FA

Does the the solution build successfully if you omit the scanner begin and scanner end steps?

Thank you @duncanp

Iv’e tried other project and now the build is successed but the scanner end step failed with this errors:

    SonarScanner for MSBuild 4.6.2
    Using the .NET Framework version of the Scanner for MSBuild
    Post-processing started.
    The SonarQube MSBuild integration failed: SonarQube was unable to collect the required information about your projects.
    Possible causes:
      1. The project has not been built - the project must be built in between the begin and end steps
      2. An unsupported version of MSBuild has been used to build the project. Currently MSBuild 14.0 and 15.0 are supported
      3. The begin, build and end steps have not all been launched from the same folder
      4. None of the analyzed projects have a valid ProjectGuid and you have not used a solution (.sln)
    Generation of the sonar-properties file failed. Unable to complete SonarQube analysis.
    11:27:03.368  Post-processing failed. Exit code: 1

i’ve tried this project:

Hi again, please, any help will be appreciated.

Tahnk you!

Try using the latest version of the SonarScanner for MSBuild.

If that doesn’t work, please provide more information.

  • Which version of MSBuild are you using?
  • Are there any messages in the MSBuild console output that start with Sonar: ?
  • Please share the commands you are running.

FYI I successfully analysed the solution by running the following commands from the root directory of the repo:

SonarScanner.MSBuild.exe begin /k:gitextensions
msbuild /t:rebuild
SonarScanner.MSBuild.exe end

Thank you @duncanp

It still doesn’t work for me.

  • Which version of MSBuild are you using?

SonarScanner for MSBuild 4.6.2

  • Are there any messages in the MSBuild console output that start with Sonar: ?

what do you mean in " MSbuild Console" I’ve ran the commands from “cmd” and the output of the “Rebuild” is all in the cmd console.
I’ve got “0” errors there:

47 Warning(s)
0 Error(s)
  • Please share the commands you are running.

I copy the commands from the Sonarqube console (localhost:9000).

1. SonarScanner.MSBuild.exe begin /k:"csharp2" /"http://localhost:9000" /d:sonar.login="91724855f2aa513413c7fa18a4fa0f6130445e02"

2. MsBuild.exe /t:Rebuild

3. SonarScanner.MSBuild.exe end /d:sonar.login="91724855f2aa513413c7fa18a4fa0f6130445e02"

My “Msbuild” is located here:

C:\Program Files (x86)\MSBuild\14.0\Bin\

Thank you!

Run msbuild -version to find the precise version of MSBuild you are using.
It needs to be at least v14.0.25420.1.

This is exactly what I have:

Microsoft (R) Build Engine version 14.0.25420.1

I’d expect to see more console output from MSBuild. When running the msbuild step, trying specifying the logging level explicitly:

msbuild /t:rebuild /v:normal

There should be messages starting "Sonar: " .e.g.


  Sonar: (NetFx35_WindowsFormsApplication1.csproj) Number of files to analyse: 6. The list of files to be analyzed is i
  n d:\code\VS2015\NetFx35_WindowsFormsApplication1\.sonarqube\out\0\FilesToAnalyze.txt.

I’m attaching the full log. I don’t see any “sonarqube” error :frowning:

Thank you @duncanp !

log.txt (56.6 KB)

@Erez_Dasa your build log is full of messages like the following:

C:\temp\csahrp\gitextensions-master\gitextensions\GitExtensions\GitExtensions.csproj.metaproj : warning MSB4078: The pr
oject file “GitExtensions\GitExtensions.csproj” is not supported by MSBuild and cannot be built.

It doesn’t look like any of the projects are being built, so none of them will be analysed either.

A quick look at the MSBuild projects in the repo shows they are in the new MSBuild “SDK” format that isn’t understood by the older v14.0.25420.1 that you are using.
You will need to upgrade to a newer version of MSBuild to build the gitextension solution (e.g. the “Build Tools for Visual Studio 2019” under the “Tools for Visual Studio 2019” on this page).

Thank you @duncanp and sorry for the delay in my answer.
I’ve downloaded the new “build tools” but it’s seems like the same error is displaying again:

     The project file "*****\*****\******.csproj" is not supported by MSBuild and cannot be built.

I don’t think the problem is in sonarqube, seems like the problem is in my build process, i’ll try to figure it out and understand what cause the problem. Any help by you and the community here will be appreciated.

Thank you!

@Erez_Dasa FYI the latest MSBuild tools can handle the older project file formats, which suggests that the build isn’t using the version of MSBuild you have just installed. Have a look a the first line of the MSBuild log output to check the expected version of the MSBuild exe is being called:

Microsoft (R) Build Engine version 16.5.0+d4cbfca49 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

Building the projects in this solution one at a time. To enable parallel build, please add the "-m" switch.
Build started 20/04/2020 11:19:02.