2

I have been using SonarQube for code analyzing at a basic level however now I would like to measure the code against FX-COP rules. Hence I am attempting to use MSBuild SonarQube scanner. I read the documentation thoroughly and have setup my project likewise however when I execute it gives me error.

Below is the extract from the log:

MSBuild SonarQube Runner Bootstrapper 1.0.2.0
Default properties file was found at C:\....\1c36691bf5270463\SonarQube.Analysis.xml
Loading analysis properties from C:\....\1c36691bf5270463\SonarQube.Analysis.xml
Pre-processing started.
Preparing working directories...
Checking for updates...
MSBuild SonarQube Runner Pre-processor 1.0.2.0
Loading analysis properties from C:\...\1c36691bf5270463\SonarQube.Analysis.xml
Updating build integration targets...
Fetching analysis configuration settings...
Generating rulesets...
Pre-processing succeeded.

Microsoft (R) Build Engine version 12.0.21005.1
[Microsoft .NET Framework, version 4.0.30319.34209]
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 11/20/2015 1:46:41 PM.
Project "C:\Project1.sln" on node 1 (rebuild target(s)).
ValidateSolutionConfiguration:
 Building solution configuration "Debug|Any CPU".
 Build succeeded.
    9 Warning(s)
    0 Error(s)

Time Elapsed 00:01:07.86
MSBuild SonarQube Runner Bootstrapper 1.0.2.0
Default properties file was found at C:\...\1c36691bf5270463\SonarQube.Analysis.xml
Loading analysis properties from C:\...\1c36691bf5270463\SonarQube.Analysis.xml
Post-processing started.

MSBuild SonarQube Runner Post-processor 1.0.2.0 gives several warnings similar to one below:

WARNING: File is not under the project directory and cannot currently be analysed
by SonarQube.
 File: C:\Users\...\AppData\Local\Temp\2\.NETFramework,Version=v4.0.AssemblyAttributes.cs,
 project: C:\...\1c36691bf5270463\SOURCE\x\y.csproj**

Calling the sonar-runner:

SONAR_RUNNER_OPTS is not configured. Setting it to the default value of -Xmx1024m
C:\...\1c36691bf5270463\.sonarqube\bin\sonar-runner\bin\..
SonarQube Runner 2.4
Java 1.8.0_51 Oracle Corporation (64-bit)
Windows Server 2008 R2 6.1 amd64
SONAR_RUNNER_OPTS=-Xmx1024m
INFO: Error stacktraces are turned on.
INFO: Runner configuration file: C:\...\1c36691bf5270463\.sonarqube\bin\sonar-runner\bin\..\conf\sonar-runner.properties
INFO: Project configuration file: C:\TeamCity\buildAgent\work\1c36691bf5270463\.sonarqube\out\sonar-project.properties
INFO: Default locale: "en_US", source code encoding: "UTF-8"
INFO: Work directory: C:\...\1c36691bf5270463\.sonarqube\out\.sonar
INFO: SonarQube Server 5.1.1
13:47:51.150 INFO  - Load global repositories
13:47:51.743 INFO  - Load global repositories (done) | time=593ms
13:47:51.758 INFO  - Server id: 20151120125423
13:47:51.758 INFO  - User cache: C:\...\cache
13:47:51.758 INFO  - Install plugins
13:47:51.836 INFO  - Install JDBC driver
.
.
.
13:47:55.518 INFO  - -------------  Scan file1
13:47:55.534 INFO  - Load module settings
13:47:55.658 INFO  - Load rules
13:47:56.017 INFO  - Base dir: C:\...\1c36691bf5270463\SOURCE\xxx
13:47:56.017 INFO  - Working dir: C:\...\1c36691bf5270463\.sonarqube\out\.sonar\AC1_AC1_497EBFF2-C710-4843-8263-F534AF803D3E
13:47:56.017 INFO  - Source encoding: UTF-8, default locale: en_US
13:47:56.532 INFO  - Quality profile for cs: Sonar way
13:48:00.635 INFO  - Sensor org.sonar.plugins.csharp.CSharpFxCopProvider$CSharpFxCopSensor@73c82ec1
INFO: -----------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: -----------------------------------------------------------------
Total time: 10.156s
Final Memory: 16M/306M
INFO: -----------------------------------------------------------------
13:48:00.791  Creating a summary markdown file...
Press any key to continue . . . 
alexandrul
  • 12,856
  • 13
  • 72
  • 99
Hitesh
  • 21
  • 1
  • 4
  • You need to run the "begin" phase by adding sonar.verbose property to true in your SonarQube.Analysis.xml available in the conf directory of SQ Scanner for MSBuild or set it directly in the command line using /d (see http://docs.sonarqube.org/display/SONAR/SonarQube+Scanner+for+MSBuild+Configuration). This will allow you to see more details about the error you have in CSharpFxCopSensor in the "end" phase. – Alexandre - SonarSource Nov 25 '15 at 08:29
  • Thanks. Error on cmd windows "The property sonar.cs.fxcop.assembly must be set and the project must have been build......." I have read many posts about this error and have done primarily everything to resolve it but it still persists. I am using a normal command window with a batch file having these commands

    MSBuild.SonarQube.Runner.exe
    begin /k:"AC1" /n:"Project1" /v:"1.0" /d:sonar.host.url=http://localhost:9000 >>log.txt
    MSBUILD.exe Project1.sln /t:rebuild >>log.txt
    MSBuild.SonarQube.Runner.exe end >>log.txt
    version of msbuild-12. Path is appropriately set. Thanks

    – Hitesh Nov 25 '15 at 13:59

3 Answers3

2

You need to run all your commands in a Developer Command Prompt for Visual Studio 2013 or higher and:

  • use at least MSBuild 12.0
  • have .NET 4.5.2+ installed

You have this error because the FxCop Results are not generated. Do you see in the MSBuild's logs, execution of FxCop? This is visible inside the RunCodeAnalysis section of MSBuild's logs.

  • I have verified the msbuild and dot net versions to be 12 and 4.5.2 I am running analysis on my CI machine (using Teacmcity). Do I need to install VS2013 on my build machine to get the VS2013 command prompt? – Hitesh Nov 25 '15 at 17:16
  • I cannot install Visual Studio 2013 on this particular server due to licensing issue. Is there any other way out? Is this same as using Windows SDK 7.1 command prompt? – Hitesh Nov 30 '15 at 16:34
  • FxCop stopped to ship as a standalone download since version 10. It now ships as part of Visual Studio. So, you're going to have to installl Visual Studio on your build agent if you'd like to get FxCop rules executed. – Dinesh Bolkensteyn Dec 08 '15 at 13:57
0

You need to run this from command line and use the "-X" flag on your command, this will give you verbose debugging, I would highly reccomend doing the following for troubleshooting.

sonar-runner.exe <arg> <arg> -X > sonar-runnerLog.txt

Then read or dump that log back here. either way you'll know a lot more about what the actual problem is.

David Hunsicker
  • 1,140
  • 3
  • 14
  • 24
-1

You can get Visual Studio Express 2013 (or 15) for free and both of those come with their respective developer command prompts.

user1282343
  • 11
  • 1
  • 3