SonarQube.Runner not compatible with C# plugin - c#

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:
Do I need to make a SonarQube project or does "SonarQube_project_key" mean the visual studio project key I want SonarQube to scan.
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.
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.
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.

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.

Related

Difference in compiling with MSBuild and Visual Studio

I'm trying to introduce SonarQube scanning to our code base. I have ASP.NET MVC web application solution. This has roughly 50 projects. The minimum project target framework is .NET 4.5.2 (Some projects are 4.6.2). I can compile this solution absolutely fine in Visual Studio 2015.
I have SonarQube 8.9.3 LTS setup on a development server.
When adding a project on SonarQube the following commands are given to execute (at the solution root) the scanner from your local machine:
Step 1:
SonarScanner.MSBuild.exe begin /k:"MyBiz" /d:sonar.host.url="http://devserver:9600" /d:sonar.login="<token>"
Step 2:
"C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" MyBiz.sln /t:Rebuild
Step 3:
SonarScanner.MSBuild.exe end /d:sonar.login="<token>"
My problem is that I get an error on step 2 during the build process:
"C:\trunk\Dev4.0\MyBiz\MyBiz.sln" (Rebuild target) (1) ->
"C:\trunk\Dev4.0\Common\src\DataLayer\DataLayer.csproj" (Rebuild target) (4) ->
(CopyFilesToOutputDirectory target) ->
C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(3813,5): error MSB3030: Could not copy the file "obj\Debug\ILRetail.eBusiness.Common.DataLayer.dll" because it was not found. [C:\trunk\Dev4.0\Common\src\DataLayer\DataLayer.csproj]
Obviously this solution compiles fine in Visual Studio so I'm guessing I'm missing some additional parameters on the MSBuild step in this process.
I'm attempted to explicitly use Configuration and Platform properties:
/property:Configuration=Debug /property:Platform="AnyCPU"
But this did not work:
The specified solution configuration "Debug|AnyCPU" is invalid
Is there something obvious I'm missing in the build command that would be the reason this works fine in Visual studio but not from command line?
Note in visual studio I would ordinarily compile using Debug & Mixed Platforms. I've attempted to use these parameters and I still get the same error as supplying no configuration/platform parameter.

How do I solve error MSB4041 (VS2017, C#, MSBuild, SpecFlow.Tools.MsBuild.Generation, SpecRun)?

I have an automation test suite, attempting to use SpecRun to run tests in parallel. It appears that rather than being able to run tests in Test Explorer, I need to instead run them using the provided "runtests.cmd" file...
#pushd %~dp0
#where /q msbuild
#IF ERRORLEVEL 1 (
echo "MSBuild is not in your PATH. Please use a developer command prompt!"
goto :end
) ELSE (
MSBuild.exe "C:\Users\me\source\repos\OurAutomation\src\OurAutomation.csproj"
)
#if ERRORLEVEL 1 goto end
#cd ..\packages\SpecRun.Runner.*\tools\net45
#set profile=%1
#if "%profile%" == "" set profile=Default
#if exist "%~dp0\bin\Debug\%profile%.srprofile" (
SpecRun.exe run "%profile%.srprofile" --baseFolder "%~dp0\bin\Debug" --log "specrun.log" %2 %3 %4 %5
) else (
SpecRun.exe run --baseFolder "%~dp0\bin\Debug" --log "specrun.log" %2 %3 %4 %5
)
:end
#popd
pause
...the pause statement is something I added in to keep the console open to see the errors.
The errors are:
Microsoft (R) Build Engine version 4.7.3056.0
[Microsoft .NET Framework, version 4.0.30319.42000]
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 08/07/2019 11:15:06.
Project "C:\Users\me\source\repos\OurAutomation\src\OurAutomation.csproj" on node 1 (defau
lt targets).
C:\Users\me\source\repos\OurAutomation\src\packages\SpecFlow.Tools.MsBuild.Generation.3.0.220\build\Sp
ecFlow.Tools.MsBuild.Generation.props(1,1): error MSB4041: The default XML namespace of the project must be the MSBuild
XML namespace. If the project is authored in the MSBuild 2003 format, please add xmlns="http://schemas.microsoft.com/d
eveloper/msbuild/2003" to the <Project> element. If the project has been authored in the old 1.0 or 1.2 format, please
convert it to MSBuild 2003 format. [C:\Users\me\source\repos\OurAutomation\src\OurAutomati
on.csproj]
Done Building Project "C:\Users\me\source\repos\OurAutomation\src\OurAutomation.csproj" (d
efault targets) -- FAILED.
Build FAILED.
"C:\Users\me\source\repos\OurAutomation\src\OurAutomation.csproj" (default target) (1) ->
C:\Users\me\source\repos\OurAutomation\src\packages\SpecFlow.Tools.MsBuild.Generation.3.0.220\build\
SpecFlow.Tools.MsBuild.Generation.props(1,1): error MSB4041: The default XML namespace of the project must be the MSBui
ld XML namespace. If the project is authored in the MSBuild 2003 format, please add xmlns="http://schemas.microsoft.com
/developer/msbuild/2003" to the <Project> element. If the project has been authored in the old 1.0 or 1.2 format, pleas
e convert it to MSBuild 2003 format. [C:\Users\me\source\repos\OurAutomation\src\OurAutoma
tion.csproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.02
I've set the system environment variable PATH to look for MSBuild.exe in C:\Windows\Microsoft.NET\Framework\v4.0.30319 (this is the latest version I have).
I tried to do as the error suggested, and found that both OurAutomation.csproj and OurAutomation.csproj.user files already have:
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
So that's the simple fix out of the way - no fix at all, because the Project tag already has the required attribute and value!
I've been on several websites looking for an alternative solution. Others are saying that they had this problem when upgrading from VS2015 to 2017 (they changed from using project.json to *.csproj). However I have not upgraded. I created my project in VS2017. Target framework: .NET Framework 4.7.2, Output type: Class Library.
Not sure if SpecFlow.Tools.MsBuild.Generation is introducing a conflict here, but I do need it.
Please do you know how I would go about fixing this? Running out of ideas.
Thank you.
Pavel Anikhouski's answer was the solution, thank you!
"Starting from VisualStudio 2015 MSBuild is provided as part of IDE (or build tools), you should use this version, e.g. c:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\".

Visual Studio Output Window warn on compile in Debug configuration

Is there any way that I can display a custom message in my Visual Studio Output window after I compile?
I had an issue today where my project was successfully compiled and a NuGet package built and released - only to find that none of my new changes had been included in the NuGet package as I had been working in Debug config and the package picked up from \bin\release\Output.dll
I would like to display a custom message in my Visual Studio Output window when I compile in Debug configuration, ideally something along the lines of:
========== Rebuild All: 11 succeeded, 0 failed, 0 skipped ==========
*** Warning - change to Release configuration before publishing ***
You can use Build events. See Project > Properties > Build Events menu.
Write Post-build event command line:
echo "*** Warning - change to Release configuration before publishing ***"

SonarQube can't complete the post-build step

I got a Jenkins Server set up on Windows 2012 R2. These are my build settings:
Underneath you see the error. It should be said that the pre-build step runs successfully:
[Test CSharp Build Job] $ ...\Jenkins\.jenkins\tools\hudson.plugins.sonar.MsBuildSQRunnerInstallation\MSBuild_2.0\MSBuild.SonarQube.Runner.exe end
SonarQube Scanner for MSBuild 2.0
Default properties file was found at ...\Documents\Jenkins\.jenkins\tools\hudson.plugins.sonar.MsBuildSQRunnerInstallation\MSBuild_2.0\SonarQube.Analysis.xml
Loading analysis properties from ...\Documents\Jenkins\.jenkins\tools\hudson.plugins.sonar.MsBuildSQRunnerInstallation\MSBuild_2.0\SonarQube.Analysis.xml
Post-processing started.
SonarQube Scanner for MSBuild End Step 1.1
No ProjectInfo.xml files were found. Possible causes:
1. The project has not been built - the end step was called right after the begin step, without a build step in between
2. An unsupported version of MSBuild has been used to build the project. Currently MSBuild 12.0 upwards are supported
3. The build step has been launched from a different working folder
Generation of the sonar-properties file failed. Unable to complete SonarQube analysis.
11:18:18.015 Creating a summary markdown file...
Post-processing failed. Exit code: 1
ERROR: Execution of SonarQube Scanner for MSBuild failed (exit code 1)
So in my Jenkins Configuration I have this:
Am I missing something to make this work?
Okay I figured it out
I forgot to add a /t:rebuild in between building with MSBuild and running the End Analysis command.

SonarQube MSBuild Runner defaults to h2 Database

I am using Win Server 2012, Developer Command Prompt for VS2013, SonarQube v5.1.2, SonarQube Scanner for MSBuild 1.1.
I have my Sonar instance running off this same server, but connected to an Oracle database. Using the default sonar runner, i can analyze projects properly and see them appear in the dashboard using this method. That cannot be said for using the recommended MSBuild.SonarQube.Runner.exe approach.
I have tried with the csharp and vbnet examples, as well as our actual code. Oddly, i want to say each of these have worked at least once, but fail to do so now. Today, I tried using the vbnet example project for the first time and discovered and it worked as intended when using the MSBuild runner. I deleted the project from the dashboard, and ran it again. At this point i do not remember it it worked or not, but the third time for sure it stopped working and began producing the error below (wherein it tries to connect to the default h2 database instead of the oracle one that SonarQube is connected to).
I tried deleting the examples folder, extracting it again, giving it a slightly different name, and running the Sonar on it giving THOSE a different name/key/version, but now it is consistently giving me the db error.
Any idea what could be going on here, and why it would go from working to not, without me making any changes to the runner, msbuild, or the code?
Running the begin step:
c:\sonar-examples-master\projects\languages\vbnet>msbuild.sonarqube.runner.exe b
egin /v:vbnet1 /k:vbnet1 /n:vbnet1
SonarQube Scanner for MSBuild 1.1
Default properties file was found at c:\sonarqube\bin\SonarQube.Analysis.xml
Loading analysis properties from c:\sonarqube\bin\SonarQube.Analysis.xml
Pre-processing started.
Preparing working directories...
Checking for updates...
MSBuild SonarQube Runner Pre-processor 1.0.2.0
17:40:49.625 Loading analysis properties from c:\sonarqube\bin\SonarQube.Analys
is.xml
17:40:49.656 Updating build integration targets...
17:40:49.656 Fetching analysis configuration settings...
17:40:50.813 Generating rulesets...
Pre-processing succeeded.
MSBuild ran, but nothing worthwhile to post from it..
Running the end step:
c:\sonar-examples-master\projects\languages\vbnet>msbuild.sonarqube.runner.exe e
nd
SonarQube Scanner for MSBuild 1.1
Default properties file was found at c:\sonarqube\bin\SonarQube.Analysis.xml
Loading analysis properties from c:\sonarqube\bin\SonarQube.Analysis.xml
Post-processing started.
MSBuild SonarQube Runner Post-processor 1.0.2.0
WARNING: File is not under the project directory and cannot currently be analyse
d by SonarQube. File: C:\Users\ts3conusr\AppData\Local\Temp\.NETFramework,Versio
n=v4.5.AssemblyAttributes.vb, project: c:\sonar-examples-master\projects\languag
es\vbnet\ConsoleApplication1\ConsoleApplication1.vbproj
The SONAR_RUNNER_HOME environment variable is not required and will be ignored.
SONAR_RUNNER_OPTS is not configured. Setting it to the default value of -Xmx1024
m
Calling the sonar-runner...
c:\sonar-examples-master\projects\languages\vbnet\.sonarqube\bin\sonar-runner\bi
n\..
SonarQube Runner 2.4
Java 1.7.0_79 Oracle Corporation (32-bit)
Windows Server 2008 R2 6.1 x86
SONAR_RUNNER_OPTS=-Xmx1024m
INFO: Error stacktraces are turned on.
INFO: Runner configuration file: c:\sonar-examples-master\projects\languages\vbn
et\.sonarqube\bin\sonar-runner\bin\..\conf\sonar-runner.properties
INFO: Project configuration file: c:\sonar-examples-master\projects\languages\vb
net\.sonarqube\out\sonar-project.properties
INFO: Default locale: "en_US", source code encoding: "UTF-8"
INFO: Work directory: c:\sonar-examples-master\projects\languages\vbnet\.sonarqu
be\out\.sonar
INFO: SonarQube Server 5.1.2
17:41:04.563 INFO - Load global repositories
17:41:04.751 INFO - Load global repositories (done) | time=188ms
17:41:04.751 INFO - Server id: 20160120154951
17:41:04.751 INFO - User cache: C:\Users\ts3conusr\.sonar\cache
17:41:04.766 INFO - Install plugins
17:41:04.860 INFO - Install JDBC driver
17:41:04.860 INFO - Create JDBC datasource for jdbc:h2:tcp://localhost/sonar
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
Total time: 1.047s
Final Memory: 3M/15M
INFO: ------------------------------------------------------------------------
ERROR: Error during Sonar runner execution
org.sonar.runner.impl.RunnerException: Unable to execute Sonar
Of note: I feel that it is worth mentioning that the vbnet report didn't actually have any content in it, but did at least properly get generated in the Sonar dashboard. I have tried running the commands against both that and the csharp example with now neither of them being added to the dashboard.
In the MSBuild.SonarQube.Runner install folder, there is a SonarQube.Analysis.xml. Do you have the correct server details on the below line in there?
<Property Name="sonar.host.url">http://{host}:{port}/{optionalPath}</Property>
This property value should point to your Sonar server.
Couple other things to try. Do you see tables being populated with analysis data in your oracle database? When was the last time it got any record?
Also, are you seeing below warning on your SonarQube application pages (say default dashboard)? If yes, then oracle configuration is not being picked up.
So i upgraded to the latest SonarQube version (5.3) and upgraded a few of the extensions while i was at it and preliminary testing is showing positive results. Ill try it a few more times but im closing the question for now. Thank you all that helped!

Categories

Resources