2
votes

I have been facing an issue with New MSBuildSonarRunner Component. I am using it for my .net project(s) analysis. Recently , I have activated some fxcop rules into my quality profile. When I run analysis on a project, it shows an error - "sonar.cs.fxcop.assembly must be set".

I am using Sonarqube 5.1.1 & Fxcop10.0 is already installed. I have changed SonarQube.Analysis.Xml file and SET below two properties.

sonar.cs.fxcop.fxCopCmdPath = C:\Program Files (x86)\Microsoft Fxcop 10.0\FxCopCmd.exe

sonar.fxcop.installDirectory=C:\Program Files (x86)\Microsoft Fxcop 10.0\

I don't see any use with these settings. I understand that even error message is also not talking about above settings.

What value I must give to "sonar.cs.fxcop.assembly" ? Where should I specify this settings - In configuration file ? or .csproj file ?

I have checked [SO post by @Dinesh][1]How to use FxCop analysis with the new MsBuild Sonar runner? It is mentioned in the post that FXCOP is natively supported. But it is not happening.

Did any one face/resolve this issue ? It has stopped our sonarqube benefits.

1
I have tried with setting assembly path for "sonar.cs.fxcop.assembly". sonar.cs.fxcop.assembly= raj\MKS\VS\MKS\bin\Debug\ABC.dll But new runner is looking for the assembly in ".Sonar" folder and throwing following exception ERROR: Caused by: Cannot find the assembly "D:\raj\MKS\VS\ MKS\.sonarqube\bin\sonar-runner\bin\raj\MKS\VS\MKS\bin\Debug\ABC.dll" provided by the property "sonar.cs.fxcop.assembly". I am not sure why is this so ?Raja Moparthi

1 Answers

1
votes

I was executing "msbuildsonarrunner" commands ( begin, msbuild , end ) from normal command prompt. Normal command prompt is configured with MsBuild path ( i.e. C:\Program Files (x86)\MSBuild\12.0\Bin). When I fire MsBuild command, Build is happening with No Fxcop Analysis. Then I checked same with Visual studio developer command prompt. Yes, Fxcop analysis is happening. I checked further to know how Visual studio command prompt is configured. In properties of VS Developer command prompt, I see Target as [ "%comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\VsDevCmd.bat"" ].

Then I switch back to normal command prompt and fired following command. CALL "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\VsDevCmd.bat". Then it started behaving as VS developer command prompt ( but obvious). It started Fxcop analysis when I fired MsBuild Command.

MsBuild command log of my dummy project is given below. I have included CA1823 fxcop rule in my quality profile. You can see warning in build log ( bold one) as I intentionally violated it.

Microsoft (R) Build Engine version 12.0.21005.1 [Microsoft .NET Framework, version 4.0.30319.34209] Copyright (C) Microsoft Corporation. All rights reserved.

Build started 10/13/2015 12:20:14 PM. Project "D:\SonarQubeProjects\Fibanocci\Fibanocci\Fibanocci.csproj" on node 1 (default targets). GenerateTargetFrameworkMonikerAttribute: Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files. CoreCompile: Skipping target "CoreCompile" because all output files are up-to-date with respect to the input files. _CopyAppConfigFile: Skipping target "_CopyAppConfigFile" because all output files are up-to-date with respect to the input files. CopyFilesToOutputDirectory: Fibanocci -> D:\SonarQubeProjects\Fibanocci\Fibanocci\bin\Debug\Fibanocci.exe OverrideCodeAnalysisProperties: Running FxCop analysis using the SonarQube ruleset. Ruleset: D:\SonarQubeProjects\Fibanocci\Fibanocci.sonarqube\conf\SonarQubeFxCop-cs.ruleset RunCodeAnalysis: Running Code Analysis... C:\Program Files (x86)\Microsoft Visual Studio 12.0\Team Tools\Static Analysis Tools\FxCop\FxCopCmd.exe /outputCulture:1033 /out:"bin\Debug\Fibanocci.exe.CodeAnalysisLog.xml" /file:"bin\Debug\Fibanocci.exe" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5.1\Microsoft.CSharp.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5.1\mscorlib.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5.1\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5.1\System.Data.DataSetExtensions.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5.1\System.Data.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5.1\System.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5.1\System.Xml.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5.1\System.Xml.Linq.dll" /directory:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5.1" /ruleSet:"=D:\SonarQubeProjects\Fibanocci\Fibanocci.sonarqube\conf\SonarQubeFxCop-cs.ruleset" /rulesetdirectory:"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Team Tools\Static Analysis Tools\Rule Sets" /rule:"-C:\Program Files (x86)\Microsoft Visual Studio 12.0\Team Tools\Static Analysis Tools\FxCop\Rules" /searchgac /ignoreinvalidtargets /forceoutput /successfile /ignoregeneratedcode /saveMessagesToReport:Active /timeout:120 MSBUILD : warning CA1823: Microsoft.Performance : It appears that field 'Program.obj' is never used or is only ever assigned to. Use this field or remove it. [D:\SonarQubeProjects\Fibanocci\Fibanocci\Fibanocci.csproj] Code Analysis Complete -- 0 error(s), 1 warning(s) SetStyleCopAnalysisSettings: Setting 'sonar.stylecop.projectFilePath' to 'D:\SonarQubeProjects\Fibanocci\Fibanocci\Fibanocci.csproj' WriteSonarQubeProjectData: Directory "D:\SonarQubeProjects\Fibanocci\Fibanocci.sonarqube\out\Fibanocci__AnyCPU_Debug_635803356164104589" doesn't exist. Skipping. Creating directory "D:\SonarQubeProjects\Fibanocci\Fibanocci.sonarqube\out\Fibanocci__AnyCPU_Debug_635803356164104589". Done Building Project "D:\SonarQubeProjects\Fibanocci\Fibanocci\Fibanocci.csproj" (default targets).

Build succeeded.

"D:\SonarQubeProjects\Fibanocci\Fibanocci\Fibanocci.csproj" (default target) (1) -> (RunCodeAnalysis target) -> MSBUILD : warning CA1823: Microsoft.Performance : It appears that field 'Program.obj' is never used or is only ever assigned to. Use this field or remove it. [D:\SonarQubeProjects\Fibanocci\Fibanocci\Fibanocci.csproj]

1 Warning(s)
0 Error(s)

Time Elapsed 00:00:01.82

It worked !!! but landed me in another problem. These issues are not getting posted to Sonar server. DashBoard is showing 0 issues, though I see Fxcop warnings in analysis results.