4

I am trying to get the following Sonar C# plugin following the instructions here: http://docs.sonarqube.org/display/PLUG/C%23+Plugin

The C# plugin installed on the server is not compatible with the MSBuild.SonarQu be.Runner.exe - either check the compatibility matrix or get the latest versions for both. Pre-processing failed. Exit code: 1"

when running step 6)a:

MSBuild.SonarQube.Runner.exe begin /k:"sonarqube_project_key" 
/n:"sonarqube_project_name" /v:"sonarqube_project_version"
  • I have tried SonarQube versions 4.5.4 (LTS) and 5.1.1
  • Developer Command Prompt for VS2012
  • I installed java (oracle): jdk-8u51-windows-x64.exe
  • Microsoft (R) Build Engine version 4.0.30319.34209
  • Running on Windows server 2012

Any ideas on how to fix this?

thanks


From MrFox:

I've added a bounty to this question and am adding my questions on this issue here:

  1. Do I need to make a SonarQube project or does "SonarQube_project_key" mean the visual studio project key I want SonarQube to scan.
  2. Even though the term 'project' is used a lot I assume this relates to the open source definition of project. Not the visual studio definition that's part of a solution.
  3. What exactly is the meaning of "sonarqube_project_version"? I've tried 6.5 (SonarQube version), 6.4.1 (SonarQubeC# plugin), 1.0.1 (MSBuild.SonarQube.Runner.exe version)

I've used the project key that's given as an example on the C# plugin website:

MSBuild.SonarQube.Runner.exe begin /k:"org.sonarqube:sonarqube-scanner-msbuild" /n:"Kadaster.Agris" /v:"1.0.1"

I've tried several permutations on these issues.
I would like to use the Analysis Bootstrapper for Visual Studio but can't find a download or explanation of how that could be done.

Edit: putting in the entire error message after request. Screenshot of console with error message In text, this also include the command I'm using after the answers that have been given so far:

> D:\projects\agris\src>MSBuild.SonarQube.Runner.exe begin
> /k:"org.sonarqube:Kadas ter_Agris" /n:"Kadaster_Agris" /v:"0.1"
> Default properties file was found at
> D:\Software\MSBuild.SonarQube.Runner.1.0.1\ SonarQube.Analysis.xml
> Loading analysis properties from
> D:\Software\MSBuild.SonarQube.Runner.1.0.1\Sona rQube.Analysis.xml
> Pre-processing started. Preparing working directories... Checking for
> updates... The C# plugin installed on the SonarQube server is not
> compatible with the Sonar Qube analysis agent (i.e. the
> MSBuild.SonarQube.Runner.exe, or the build automat ion task). Either
> check the compatibility matrix or get the latest versions for both.
> Pre-processing failed. Exit code: 1

The first step is to do pre-processing:

> D:\projects\agris\src>D:\Software\sonar-scanner-msbuild-3.0.2.656\MSBuild.SonarQ
> ube.Runner.exe begin /k:"myCompanyHostedSonarQube:GMA_Kadaster_Agris"
> /n:"Kadas ter_Agris" /v:"0.1" SonarQube Scanner for MSBuild 3.0.2
> Default properties file was found at
> D:\Software\sonar-scanner-msbuild-3.0.2.656 \SonarQube.Analysis.xml
> Loading analysis properties from
> D:\Software\sonar-scanner-msbuild-3.0.2.656\Son arQube.Analysis.xml
> Pre-processing started. Preparing working directories... 09:08:16.861 
> Updating build integration targets... 09:08:16.879  Fetching analysis
> configuration settings... 09:08:17.971  Generating rulesets...
> 09:08:17.993  Provisioning analyzer assemblies for cs... 09:08:17.994 
> Installing required Roslyn analyzers... 09:08:18.507  Pre-processing
> succeeded.

Then the project must be rebuild.
Then tell SonarQube to end and send everything to the server, this last step fails:

> Done Building Project "D:\projects\agris\src\Kadaster.Agris.sln"
> (Rebuild targe t(s)).
> 
> 
> Build succeeded.
> 
> "D:\projects\agris\src\Kadaster.Agris.sln" (Rebuild target) (1) ->
> "D:\projects\agris\src\Kadaster.Agris.Web\Kadaster.Agris.Web.csproj.metaproj"
> ( Rebuild target) (13) ->
> "D:\projects\agris\src\Kadaster.Agris.Web\Kadaster.Agris.Web.csproj"
> (Rebuild t arget) (14) -> (CoreCompile target) ->  
> Controllers\OutputController.cs(48,30): warning CS0168: The variable
> 'ex' is declared but never used
> [D:\projects\agris\src\Kadaster.Agris.Web\Kadaster.Agri s.Web.csproj] 
> Controllers\OutputController.cs(80,30): warning CS0168: The variable
> 'ex' is declared but never used
> [D:\projects\agris\src\Kadaster.Agris.Web\Kadaster.Agri s.Web.csproj] 
> Controllers\OutputController.cs(166,30): warning CS0168: The variable
> 'ex' is  declared but never used
> [D:\projects\agris\src\Kadaster.Agris.Web\Kadaster.Agr is.Web.csproj]
> 
>     3 Warning(s)
>     0 Error(s)
> 
> Time Elapsed 00:00:08.91
> 
> D:\projects\agris\src>D:\Software\sonar-scanner-msbuild-3.0.2.656\MSBuild.SonarQ
> ube.Runner.exe end SonarQube Scanner for MSBuild 3.0.2 Default
> properties file was found at
> D:\Software\sonar-scanner-msbuild-3.0.2.656 \SonarQube.Analysis.xml
> Loading analysis properties from
> D:\Software\sonar-scanner-msbuild-3.0.2.656\Son arQube.Analysis.xml
> Post-processing started. The SonarQube MSBuild integration failed:
> SonarQube was unable to collect the re quired information about your
> projects. Possible causes:
>   1. The project has not been built - the project must be built in between the b egin and end steps
>   2. An unsupported version of MSBuild has been used to build the project. Curre ntly MSBuild 14.0 upwards are supported
>   3. The begin, build or end steps have not all been launched from the same fold er Generation of the sonar-properties file failed. Unable to
> complete SonarQube ana lysis. 14:38:26.197  Creating a summary
> markdown file... 14:38:26.2  Post-processing failed. Exit code: 1

The three warnings are about unused exception variables.

MrFox
  • 4,852
  • 7
  • 45
  • 81
Yogi Valani
  • 461
  • 3
  • 11
  • You list two sonarqube versions, but have you verified that the version of the c# plugin that's installed on the server is what you think it is? Installing SonarQube proper does not automatically update plugins. – Levesque Jul 24 '15 at 14:35
  • Thanks for the quick response. How do I verify the version of the C# plugin? I downloaded the C# 4.0 plugin from http://docs.sonarqube.org/display/PLUG/C%23+Plugin. Installed it manually by copying the jar to $SONARQUBE_HOME/extensions/plugins. (followed guide http://docs.sonarqube.org/display/SONAR/Installing+a+Plugin) – Yogi Valani Jul 24 '15 at 14:51
  • You can verify the version you have installed by logging in as an administrator and going to settings..system..update center (in Sonar 5.1). Look for the update center in earlier versions too, it's still under settings but iirc the location is a bit different. – Levesque Jul 24 '15 at 15:02
  • Thanks for that, installed version is C# 4.0 plugin – Yogi Valani Jul 24 '15 at 15:22
  • Sorry, that's all I have to suggest... we use the analysis bootstrapper, not the msbuild plugin. – Levesque Jul 24 '15 at 15:37
  • Thank you for your response, Levesque. I will try the analysis bootstrapper see if I can get that running. – Yogi Valani Jul 27 '15 at 09:13
  • Questions: 1. Do I need to make a SonarQube project or does "SonarQube_project_key" mean the visual studio project key I want SonarQube to scan. 2. Even though the term 'project' is used a lot I assume this relates to the open source definition of project. Not the visual studio definition that's part of a solution. I've tried several permutations on these issues. – MrFox Oct 08 '17 at 18:19

1 Answers1

2

Do I need to make a SonarQube project or does "SonarQube_project_key" mean the visual studio project key I want SonarQube to scan.

The key specified by /k: will be used as the unique key to identify your project on SonarQube server. It can be anything, and it's really up to you. A common choice for example is the name of the solution in Visual Studio.

The /n: parameter defines the display name to use on SonarQube.

The /v: parameter defines the version of your project that your analysis represents. One of the main purposes of SonarQube is to track the code quality changes in the so-called leak period, which is the time since the last release. The metrics of the leak period reset when the version changes. SonarQube doesn't assume the version of your project, you tell it yourself explicitly.

Even though the term 'project' is used a lot I assume this relates to the open source definition of project. Not the visual studio definition that's part of a solution.

The term 'project' in SonarQube documentation refers to the representation on SonarQube. In Visual Studio terms, it corresponds to the 'solution'. You typically create one SonarQube project per Visual Studio solution. This is a matter of how you want to look at your quality metrics. It usually makes sense to aggregate the metrics of all Visual Studio projects under one dashboard in SonarQube.

I would like to use the Analysis Bootstrapper for Visual Studio but can't find a download or explanation of how that could be done.

That's obsolete. You should not need that anymore, at the time of this writing.


It seems you're using a very old version of Scanner for MSBuild. You can download the latest version from here, try with this one:

https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+MSBuild

However, note that current versions of Scanner for MSBuild require MSBuild version 14 or higher. That implies that your project needs to be built with Visual Studio 2015 or higher. If your project uses an older version, you will have to migrate it.

janos
  • 120,954
  • 29
  • 226
  • 236
  • Thanks for your answers, this basically means the parameters relate to a project that's created on SonarQube, not a reference to my source code. I'm getting exactly the same error message, but I'll edit the full message in. I think my questions are valid additions to the original question and the version is just an update to the newer versions. Otherwise people will think it's a duplicate question. – MrFox Oct 08 '17 at 20:29
  • @MrFox it seems you're using a very outdated version of Scanner for MSBuild. Download the latest from here: https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+MSBuild – janos Oct 08 '17 at 20:55
  • Mine is a .jar, yours is .exe. Everything in the SonarQube software that I downloaded is .jar (so java package instead of .exe packaged), maybe that's the problem? I replaced the 'sonarqube-6.5/lib/scanner' with your folder, it doesn't help. I'm starting the StartSonar.bat with Administrator privileges in 'sonarqube-6.5\bin\windows-x86-64'. – MrFox Oct 09 '17 at 05:54
  • @MrFox your comment is about SonarQube. My comment is about Scanner for MSBuild. The Download link at the top of the page linked in my previous comment is this: https://github.com/SonarSource/sonar-scanner-msbuild/releases/download/3.0.2.656/sonar-scanner-msbuild-3.0.2.656.zip It contains `SonarQube.Scanner.MSBuild.exe` that you need to use to scan your project and push an analysis to your SonarQube. – janos Oct 09 '17 at 07:00
  • I've configered the scanner and executed it with the command and it says pre-processing succeeded, but nothing else. No analysis or output. Will elaborate in edit. – MrFox Oct 09 '17 at 07:12
  • @MrFox It looks like you executed Step 1, and it succeeded. You can proceed to step 2, `MSBuild.exe /t:Rebuild`, and step 3, `SonarQube.Scanner.MSBuild.exe end`. – janos Oct 09 '17 at 08:10
  • Thanks, it still produces an error though :( The SonarQube MSBuild integration failed: SonarQube was unable to collect the required information about your projects. Will put the full error in the original question. – MrFox Oct 09 '17 at 12:41
  • @MrFox What is the version of your `MSBuild.exe`, and the version of Visual Studio you usually build your solution, and the target platform of your builds? Btw somehow the output is not pasted well, it's really hard to read. If it's difficult to copy-paste from the terminal, you could redirect output to a text file with `somecmd > output.txt` and copy-paste from that file. And then in the question, you can highlight the pasted code and press control-k to format it as code. That should be easy to read. – janos Oct 09 '17 at 13:16
  • It's in: C:\Windows\Microsoft.NET\Framework64\v4.0.30319, but I have tons of .NET versions installed in my programs list: 4.5, 4.5.1, 4.5.2, 4.6, 4.6.2. I normally build my Visual Studio solution in 2013 update 5. – MrFox Oct 09 '17 at 14:03
  • @MrFox What's the output of `msbuild /version` ? – janos Oct 09 '17 at 14:09
  • I did it with the full file path, don't have it in my path: 4.6.1590.0 – MrFox Oct 09 '17 at 14:19
  • @MrFox that looks like a .NET framework version, not msbuild version. I suspect you have MSBuild version 12.x, which is no longer supported with the latest SonarC# and Scanner-for-MSBuild (as the output tells you). If you cannot upgrade to Visual Studio 2015 (which will imply MSBuild 14.x), then you will need to use older SonarC# and older Scanner-for-MSBuild – janos Oct 09 '17 at 14:22
  • Thanks, I was using the MSBuild from .NET Framework. Used the one from Visual Studio 2015 instead, now it works! Will accept the bounty in two hours. – MrFox Oct 09 '17 at 15:02
  • this post solved my problem, I was pointing to older version of MSBuild: https://stackoverflow.com/a/26443520/1732411 – tgondar Dec 19 '17 at 12:12