I am checking the documentation for sonarqube msbuild scanner. But I can't find the SonarQube.Scanner.MSBuild.exe in the distribution given. So when I point the bin directory and run sonar command given in that page
SonarQube.Scanner.MSBuild.exe begin /k:"org.sonarqube:sonarqube-scanner-msbuild" /n:"Project Name" /v:"1.0"
MSBuild.exe /t:Rebuild
SonarQube.Scanner.MSBuild.exe end
I got an error saying
'SonarQube.Scanner.MSBuild.exe' is not recognized as an internal or external command,
Since this exe file is not in the distribution and it runs using sonar-scanner bat file what is the correct command to run the project?
When I using sonar-scanner instead of SonarQube.Scanner.MSBuild.exe, it complains about /k option.
You need to download the latest version of SonarScanner for MsBuild. The zip file contains all needed executables.
You should not use sonar-scanner for analyzing .NET projects.
Related
I'm at a total loss. We have TeamCity installed (TeamCity Professional 2017.2.3 (build 51047)). We run the MSBuild step with:
MSBuildVersion: Microsoft Build Tools 2017
MSBuild Tools Version:
15.0
and Command Parameters:
/t:Clean /p:DeployOnBuild=true /t:build /t:publish /p:PublishProfile=Properties\PublishProfiles\Deploy.pubxml /p:PublishDirectory=Deployment /p:Configuration=Release /p:VisualStudioVersion=15.0
When we run the build t shows:
_DeploymentUnpublishable [11:16:53][_DeploymentUnpublishable] Skipping unpublishable project.
TeamCity outputs at the start:
Starting:
C:\TeamCity\buildAgent\plugins\dotnetPlugin\bin\JetBrains.BuildServer.MsBuildBootstrap.exe
/workdir:C:\TeamCity\buildAgent\work\c36dd5b119aec7b
"/msbuildPath:C:\Program Files (x86)\Microsoft Visual
Studio\2017\BuildTools\MSBuild\15.0\bin\MSBuild.exe"
If I navigate to the msbuildPath in the CommandLine and run the same command it builds and publishes without issue.
Any help would be greatly appreciated.
MSBuild Step In TeamCity:
I had this issue and resolved it by setting a Parameter towards the publishing profile.
This is what i had:
- *.csproj would build and publish in visual studio locally.
- TeamCity builds fine but when asked to Publish sends me the not helpful _deploymentunpublishable
I tried all the commands in the msbuild line but only the following setup works:
pre-step: Create a Publishing profile (*.pubxml) which outputs to a folder within your build. This should be saved in your /Properties folder of the build.
inside your configuration page, go to Parameters.
Add a new Parameter for "System". Call it PublishProfile (system.PublishProfile). Give it a vaule which is the name of your publish profile file or *.pubxml
enter image description here
create a new step (or amend existing publish step), runner type "MSBuild" and in the Targets box type WebPublish
enter image description here
You dont need any command line parameters as your pubxml will handle all this.
Thats it, give it a try and your code should now publish to the folder you set in the publishing profile.
I installed like these...
sonarqube-6.2 | sonar-scanner-2.8 | sonar-scanner-msbuild-2.2.0.24 | msbuild 14
And I made windows batch file to build and scan(sonar). but some projects are ok. but some projects are failed.
batch file is...
MSBuild.SonarQube.Runner.exe begin /k:%PROJECT_KEY% /n:%PROJECT_NAME% /v:%BUILD_VERSION% /d:sonar.verbose=true
MSBuild.exe "projects" /t:build /v:m
MSBuild.SonarQube.Runner.exe end
error message is...
SonarQube Scanner for MSBuild 2.2
Default properties file was found at C:\SONARQUBE\sonar-scanner-msbuild-2.2.0.24\SonarQube.Analysis.xml
Loading analysis properties from C:\SONARQUBE\sonar-scanner-msbuild-2.2.0.24\SonarQube.Analysis.xml
Post-processing started.
SonarQube Scanner for MSBuild 2.2
18:50:20.591 Loading the SonarQube analysis config from C:\jenkins_slave_buildpc\workspace\amis3_client_sonar.sonarqube\conf\SonarQubeAnalysisConfig.xml
18:50:20.592 Not running under TeamBuild
18:50:20.593 Analysis base directory: C:\jenkins_slave_buildpc\workspace\amis3_client_sonar.sonarqube
Build directory:
Bin directory: C:\jenkins_slave_buildpc\workspace\amis3_client_sonar.sonarqube\bin
Config directory: C:\jenkins_slave_buildpc\workspace\amis3_client_sonar.sonarqube\conf
Output directory: C:\jenkins_slave_buildpc\workspace\amis3_client_sonar.sonarqube\out
Config file: C:\jenkins_slave_buildpc\workspace\amis3_client_sonar.sonarqube\conf\SonarQubeAnalysisConfig.xml
Generating SonarQube project properties file to C:\jenkins_slave_buildpc\workspace\amis3_client_sonar.sonarqube\out\sonar-project.properties
The SonarQube MSBuild integration failed: SonarQube was unable to collect the required information about your projects.
Possible causes:
The project has not been built - the project must be built in between the begin and end steps
An unsupported version of MSBuild has been used to build the project. Currently MSBuild 12.0 upwards are supported
The begin, build or end steps have not all been launched from the same folder
Writing processing summary to C:\jenkins_slave_buildpc\workspace\amis3_client_sonar.sonarqube\out\ProjectInfo.log
Generation of the sonar-properties file failed. Unable to complete SonarQube analysis.
18:50:20.615 Creating a summary markdown file...
18:50:20.617 Post-processing failed. Exit code: 1
I executed same batch file for sonar. but some project is ok. and some project is failed..
What makes this error message?
I got the similar error when trying to run MSBuild.SonarQube.Runner end command in teamcity.
Begin step and MSBuild step to build project was working fine.
When I given full path for runner and MSbuild in teamcity. It worked for me.
C:\SonarQube\sonar-scanner-msbuild-3.0.2.656\MSBuild.Sonarqube.runner.exe
begin /k:"Sonar key here" /n:"Sonar project here" /v:%build.number%
/d:sonar.log.level=DEBUG
"C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" [path for .sln file
here] /t:Rebuild
/p:VisualStudioversion=14.0;Configuration=Release;Platform="Any CPU"
C:\SonarQube\sonar-scanner-msbuild-3.0.2.656\MSBuild.Sonarqube.runner end
Another thing worth checking--especially if you're trying to run SonarQube from a build server--is whether it is operating in the local system profile. From the logs, you may see something like:
Installed SonarQube.Integration.ImportBefore.targets to C:\Windows\system32\config\systemprofile\AppData\Local\Microsoft\MSBuild\15.0\Microsoft.Common.targets\ImportBefore
I found that this path did not exist, even though SonarQube's scanner happily claimed to have installed its targets there. My solution was to create a build agent account for executing the build tasks. This will cause SonarQube to install its targets to the user profile MSBuild folder. For example:
C:\Users\buildagent\AppData\Local\Microsoft\MSBuild\15.0\Microsoft.Common.targets\ImportBefore
I am using SonarQube 5.2 for calculating the metrics.
Everything works fine, when I run it using "Developer Command Prompt for VS2013".
But when I run the same commands using normal command prompt "cmd.exe" with or without administrator rights, I am getting the following error
C:\Windows\system32>"C:\sonarqube-5.2\bin\MSBuild.SonarQube.Runner.exe" end
SonarQube Scanner for MSBuild 1.1
Default properties file was found at C:\sonarqube-5.2\bin\SonarQube.Analysis.xml
Loading analysis properties from C:\sonarqube-5.2\bin\SonarQube.Analysis.xml
Post-processing started.
MSBuild SonarQube Runner Post-processor 1.0.2.0
11:39:29.774 sonar.verbose=true was specified - setting the log verbosity to 'Debug'
11:39:29.774 Loading the SonarQube analysis config from C:\Windows\system32\.sonarqube\conf\SonarQubeAnalysisConfig.xml
11:39:29.774 Not running under TeamBuild
11:39:29.774 Analysis base directory: C:\Windows\system32\.sonarqube
Build directory:
Bin directory: C:\Windows\system32\.sonarqube\bin
Config directory: C:\Windows\system32\.sonarqube\conf
Output directory: C:\Windows\system32\.sonarqube\out
Config file: C:\Windows\system32\.sonarqube\out
Generating SonarQube project properties file to C:\Windows\system32\.sonarqube\out\sonar-project.properties
No ProjectInfo.xml files were found. Possible causes: you specified an invalid build configuration or the custom MSBuild analysis targets were not imported.
Writing processing summary to C:\Windows\system32\.sonarqube\out\ProjectInfo.log
Generation of the sonar-properties file failed. Unable to complete SonarQube analysis.
11:39:29.79 Creating a summary markdown file...
Post-processing failed. Exit code: 1
Please let me know what could be isssue and how to resolve it.
The following steps are followed by me,
Executed all the commands from one location example - "D:\Test"
Added the following in the PATH environment variable
a. path to MSBUILD's 12.0 folder
The commands executed for analysis of metrics,
a. MSBuild.SonarQube.Runner.exe begin
b. MSBuild abc.csproj /t:Clean;Rebuild /p:VisualStudioVersion=12.0...;
c. MSBuild.SonarQube.Runner.exe end
I got the solution.
I should use the full path to MSBuild instead of putting it in the PATH variable, which causes this issue for SonarQube Analysis.
-->
MSBuild.SonarQube.Runner.exe begin
"%programfiles(x86)%\msbuild\12.0\bin\MSBuild.exe" abc.csproj /t:Clean;Rebuild /p:VisualStudioVersion=12.0...;
MSBuild.SonarQube.Runner.exe end
<--
I think, any command that requires Developer Command Prompt, should also work in the normal command prompt, provided the path to MSBUILD should be in full.
Regards,
Guru
This worked well. :)
Use the below lines code one by one after each exection is completed:
SonarQube.Scanner.MSBuild.exe begin /k:"ProjectKeyName" /n:"ProjectName" /v:"1.0"
"C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" /t:Rebuild
SonarQube.Scanner.MSBuild.exe end
Note:
Please replace the ProjectKeyname and projectName with yours (As per sonar-project.properties file created under your Project Root Folder)
Version used:
sonarqube-5.6.6 (tested in sonarqube-6.4 as well),
sonar-scanner-msbuild-3.0.0.629
I have a TFS xaml Build template that runs the msbuild.sonarqube.runner start (and end) before and (after the) msbuild task in the xaml.
It all works well enough with a .sln file. As the file under build.
However, when I attempt to use this on a build that runs msbuild on a .csproj file the end process reports that it cannot find the postprocess exe.
"Execution failed. The specified executable does not exist: .sonarqube\bin\MSBuild.SonarQube.Internal.PostProcess.exe"
there no error indication given by the Start command.
is there something special I need to do to get this to work, or is this a limitation of the MSBuild runner?
Please help.
My whole team is keen to use the tool, but as it is only a fraction of the existing builds are being analyzed
thanks
Jeff Gedney
The begin and end commands of the SonarQube Scanner for MSBuild, as well as all msbuild commands MUST be launched from the same current working directory. Indeed, they will all need access to the .sonarqube folder that is created by the begin command.
Other than that, you can launch MSBuild on a *.csproj file instead of a *.sln if you prefer - that is supported by the SonarQube Scanner for MSBuild.
I've created the following ticket to improve the error message in case end is launched from the wrong folder: https://jira.sonarsource.com/browse/SONARMSBRU-160
Make sure you put yourself in the root folder of the project you want to analyze, then run the following commands:
a.MSBuild.SonarQube.Runner.exe begin /k:"sonarqube_project_key" /n:"sonarqube_project_name" /v:"sonarqube_project_version"
b.Build the project, for example: msbuild /t:Rebuild
c.MSBuild.SonarQube.Runner.exe end
Check:http://docs.sonarqube.org/display/PLUG/C%23+Plugin
We use TeamCity as our build server - how does one setup TeamCity to run SonarQube analysis for C# / .NET solutions?
I'm thinking we'll need to execute the MSBuild runner as a command line task since the TeamCity SonarQube runner doesn't call the MSBuild SonarQube runner.
(It would be great if http://docs.sonarqube.org/display/PLUG/C%23+Plugin described this scenario.)
EDIT
The URL in the original post has changed. Correct link is here.
You're right: There are build step/tasks for the MSBuild SonarQube Runner available out-of-the-box for Team Foundation Server 2015 (and soon Jenkins) - but not for TeamCity. You indeed need to use the command line step/task to manually invoke the MSBuild SonarQube Runner begin and end phase, and MSBuild in between.
From there, the actual configuration and usage is identical to the command line scenario, which is why the TeamCity doesn't have its own documentation.
Here is what I did to run this via a build task
Put the following command as a .cmd file in the solution root
cd %system.agent.home.dir%
C:\sonarqube\bin\MSBuild.SonarQube.Runner.exe begin /key:MyKey /name:MyProjectName /version:1
"C:\Program Files (x86)\MSBuild\14.0\Bin\msbuild.exe" MySolution.sln /t:Rebuild
C:\sonarqube\bin\MSBuild.SonarQube.Runner.exe end
Create a "Command" task in TeamCity and execute the .cmd file