Documentation needed on how to get FXCop running with Sonarqube 5.1 - c#

On the sonarqube website the new C# plugin documentation states 'native support for fxcop'
However there is no explanation how to get fxcop running. It does not work out of the box.
What i did so far and works:
installed Sonarqube 5.1
using msbuild.sonarqube.runner
The sonarqube C#,xml,js analysis al work like a charm.
What does not work is using fxcop rules.When i enable 1 rule i get the runner to give the following exception:
ERROR: Error during Sonar runner execution
org.sonar.runner.impl.RunnerException: Unable to execute Sonar
at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLaunc
her.java:91)
at org.sonar.runner.impl.BatchLauncher$1.run(BatchLauncher.java:75)
at java.security.AccessController.doPrivileged(Native Method)
at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:69)
at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50)
at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:102
at org.sonar.runner.api.Runner.execute(Runner.java:100)
at org.sonar.runner.Main.executeTask(Main.java:70)
at org.sonar.runner.Main.execute(Main.java:59)
at org.sonar.runner.Main.main(Main.java:53) Caused by: java.lang.IllegalArgumentException: The property "sonar.cs.fxcop.a
ssembly" must be set and the project must have been built to execute
FxCop ru les. This property can be automatically set by the Analysis
Bootstrapper for Visual Studio Projects plugin, see:
http://docs.codehaus.org/x/TAA1Dg.If you wish to skip the analysis of
not built projects, set the property "sonar.visu
alstudio.skipIfNotBuilt".
What i tried so far:
followed the provided docs.codehaus.org/x/TAA1Dg link but this is a dead link. It states "All Codehaus services have been terminated".
added sonar.cs.fxcop.assembly property to the sonarqube.analysis.xml but this does not change anything to the error.
added sonar.cs.fxcop.installdirectory property to the sonarqube.analysis.xml file. This changes the error messages to:
Caused by: java.lang.IllegalArgumentException: Cannot find the
assembly "C:\p
rojects\mercurial\ccvs.sonarqube\bin\sonar-runner\bin\"FxCopCmd.exe""
provided by the property "sonar.cs.fxcop.assembly".
But i'm unable to the the fxcop installation copied to this folder. I also failed to influence the path to be redirected to my fxcop installation which comes with vs2013(C:\Program Files (x86)\Microsoft Visual Studio 12.0\Team Tools\Static Analysis Tools\FxCop\FxCopCmd.exe)
Another thing is that the sonar-project.properties file next to the .sln file is not picked up by this new msbuild sonar runner thats why i edit the xml file.
In short a step-by-step on the guide how to get fxcop working together with sonarqube 5.1 and the msbuild sonarrunner on the site of sonarqube would be appreciated.

I thinks you should read
http://www.sonarqube.org/easy-analysis-of-visual-studio-solutions-with-the-sonarqube-scanner-for-msbuild/
and
http://docs.sonarqube.org/display/PLUG/C%23+Plugin .
Pay attention to the fact that you should run the commands from a "Developer Command Prompt for Visual Studio 2013 or higher" (http://docs.sonarqube.org/display/SONAR/Analyzing+with+SonarQube+Scanner+for+MSBuild).
Neither DOS Command Prompt nor Windows PowerShell work because they don't set the proper variables.
The FxCop native support doesn't mean that it comes with MSBuild SonarQube Runner, but you have to install Visual Studio >= 2013 (as I think you understood from your message).
Moreover, I found that not only sonar-project.properties has been deprecated, but you have to remove it to avoid strange behaviors.

Related

Dotnet: Works in VSCode's OWN TERMINAL, but OMNISHARP: 'dotnet.exe' is not recognized

How is this possible?
I installed .net sdk 6.0.405: dotnet-sdk-6.0.405-win-x64.exe
I can in windows terminal and power shell run: dotnet --version: 6.0.405 ✅
I CAN ALSO IN VSCODE IN ITS BUILTIN TERMINAL, run: dotnet --version: 6.0.405 ✅✅
But in the OUTPUT tab, choosing OmniSharp Log from the dropdown, it says:
[ERROR] A .NET 6 SDK for x86_64 was not found. Please install the latest x86_64 SDK from ...
I switched vscode explorer settings to use external terminal.
And this terminal setting to command prompt:
Terminal › Integrated › Default Profile: Windows
The default profile used on Windows. This setting will currently be ignored if either terminal.integrated.shell.windows or terminal.integrated.shellArgs.windows are set.
I have dotnet in the PATH (and it works in terminals and in vscode's terminal)
I restarted vscode, AND REINSTALLED the dotnettools "C# for Visual Studio Code (powered by OmniSharp)" extension. I went to the online store and from the right column under Resources I downloaded the ms-dotnettools.csharp-1.25.2#win32-x64.vsix to make sure I get the right one. And restarted vscode.
I tried this setting:
Omnisharp: Dotnet Path
Specified the path to a dotnet installation to use when "useModernNet" is set to true, instead of the default system one. This only influences the dotnet installation to use for hosting Omnisharp itself. Example: "/home/username/mycustomdotnetdirectory".
C:/Program Files/dotnet/sdk/6.0.405
And this setting:
Omnisharp: Sdk Path
Specifies the path to a .NET SDK installation to use for project loading instead of the highest version installed. Applies when "useModernNet" is set to true. Example: /home/username/dotnet/sdks/6.0.300.
C:/Program Files/dotnet/sdk/6.0.405
And restarted vscode. And now it says:
[ERROR] Error: Command failed: dotnet.exe --version
'dotnet.exe' is not recognized as an internal or external command,
operable program or batch file.
What? W H A T? lol
What could be wrong? Why isn't it saying where it expected to find it and what to do to locate it? Is there a setting to specify the dotnet.exe path to this C# extension? Does it need always-on internet or something? Does it have DRM? Does it need Edge installed? Wtf?🙂
🙃😭 I just need intellisense; and I've wasted 2h, on only microsoft-owned products.
#Microsoft 0/5 stars
Still don't know why it happens, but here's how to solve it:
The problem was from this: I like to keep all my visual studio code extensions as .vsix files locally in folders so I can remember and get them easily & offline. Sensible enough choice, and I had the correct ms-dotnettools.csharp-1.25.2#win32-x64.vsix for my platform.
But in VSCode, when I install this particular extension via VSIX, even though it succeeds, it can't find .net. If you instead install the extension "normally", ie via vscode's own download, it seems vscode does some extra configuration steps while installing, and probably sets the .net paths correctly or something. Because now it works.
So TL;DR: don't install ms-dotnettools.csharp via vsix, it seems bugged. 😶
Would love to see an answer explaining what's wrong / how to actually do via vsix; but I don't have any more time to debug this rn.

SonarQube unrecognized command line argument c#

I'm having trouble running a scann for my c# app, I'm trying to scan a simple console application. but everytime I run my analysis I get this:
16:00:04.919 16:00:04.919 Unrecognized command line argument: /t:Rebuild
So here's the complete command since the beginning:
PS C:\Users\danie\documents\Visual Studio 2015\Projects\ConsoleApplication1> C:\SonarQube-Scanner-for-MSBuild\SonarQube.Scanner.MSBuild.exe begin /k:"ConsoleApplication1" /n:"ConsoleApplication1"/v:"1.0"
SonarQube Scanner for MSBuild 4.0.2
Default properties file was found at C:\SonarQube-Scanner-for-
MSBuild\SonarQube.Analysis.xml
Loading analysis properties from C:\SonarQube-Scanner-for-
MSBuild\SonarQube.Analysis.xml
Pre-processing started.
Preparing working directories...
16:13:12.659 Updating build integration targets...
16:13:12.674 Fetching analysis configuration settings...
16:13:13.051 Provisioning analyzer assemblies for cs...
16:13:13.052 Installing required Roslyn analyzers...
16:13:13.152 Pre-processing succeeded.
PS C:\Users\danie\documents\Visual Studio 2015\Projects\ConsoleApplication1>
C:\SonarQube-Scanner-for-MSBuild\SonarQube.Scanner.MSBuild.exe /t:Rebuild
SonarQube Scanner for MSBuild 4.0.2
Default properties file was found at C:\SonarQube-Scanner-for-
MSBuild\SonarQube.Analysis.xml
Loading analysis properties from C:\SonarQube-Scanner-for-
MSBuild\SonarQube.Analysis.xml
WARNING: Please specify the command 'begin' or 'end' to indicate whether
pre- or post-processing is required. These parameters will become mandatory
in a later release.
Pre-processing started.
Preparing working directories...
16:13:17.069 16:13:17.053 Unrecognized command line argument: /t:Rebuild
16:13:17.069 16:13:17.053 A required argument is missing: /key:[SonarQube
project key]
16:13:17.069 Expecting at least the following command line argument:
- SonarQube project key
When connecting to a SonarQube server earlier than version 6.1, the following command line arguments are also required:
- SonarQube project name
- SonarQube project version
The full path to a settings file can also be supplied. If it is not supplied, the exe will attempt to locate a default settings file in the same directory as the SonarQube Scanner for MSBuild.
Use '/?' or '/h' to see the help message.
16:13:17.084 Pre-processing failed. Exit code: 1
Any help fixing this will be appreciatted!
Thanks.
PD: I'm running sonarqube version 6.7.1 and MSBuild
The second command you execute should be just msbuild.exe, not SonarQube.Scanner.MSBuild.exe.
Edit:
The problem, is indeed that I have to execute MSBuild.exe instead of the other one but if you can't execute that, it may be because you don't haven't configured your environment varables, and path. If you can't execute it simply look for your MSBuild folder in Program Files (x86), in the end you should execute this:
'C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe' /t:Rebuild
so this should be it.

SonarQube analysis could not be completed because the analysis configuration file could not be found

SonarQube is giving me below error when i integrate the xamarin app with jenkins on windows sever
SonarQube Scanner for MSBuild 3.0
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.
13:49:43.952 SonarQube analysis could not be completed because the analysis configuration file could not be found: C:\Users\Administrator\.jenkins\workspace\Xamarin-ProjectTemplate\.sonarqube\conf\SonarQubeAnalysisConfig.xml.
13:49:43.952 Post-processing failed. Exit code: 1
I have followed the below guide https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+MSBuild
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
Please help me to resolve this issue
The errors reported at the end of a SonarQube report are sometimes less helpful than the errors when you begin.
Eg when I got this error, scrolling to the top of the log showed that I wasn't correctly setting the sonar.projectKey value, but this message the OP shared is still what showed up at the end.
I had the same problem. You need find correct MSBuild.exe.
I have several in c:\Windows\Microsoft.NET\Framework64\... and also in c:\Program Files (x86)
For my project in Visual Studio 2017 with .NETFramework,Version=v4.6.1 the correct MSBuild.exe is:
"c:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\amd64\MSBuild.exe" /t:Rebuild
For the Enterpsie version is should be:
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild" /t:Rebuild
I got the same error and was able to fix it by excluding "/t:Rebuild" from second step. Also used the VS2017 MSBuild.exe
These are the 3 commands I ran in Windows Command Prompt (CMD):
1>> SonarScanner.MSBuild.exe begin /k:"MyProjectName"
2>> "C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/MSBuild/15.0/Bin/MSBuild.exe" "MySolution.sln"
3>> SonarScanner.MSBuild.exe end
Update I confront this error also , my solution was easy I just build the project in the visual studio then its succeeded.
I had this problem because I used a bad project key (it had a }) inside. I removed the }and the problem was gone.

How to set FxCop installation path using SonarQube's C# plugin

I'm trying to analyze .NET C# project using SonarQube C# plugin.
From C# Plugin 3.0, FxCop is automatically executed even thogh "sonar.fxcop.mode=skip" in sonar-project.properties, so I installed FxCop to following directory.
C:\Program Files (x86)\Microsoft FxCop 1.35
When I ran SonarQube Runner from Jenkins's sonar plugin, then I got following error.
ERROR: Error during Sonar runner execution
ERROR: Unable to execute Sonar
ERROR: Caused by: The property "sonar.cs.fxcop.assembly" must be set.
ERROR:
ERROR: To see the full stack trace of the errors, re-run SonarQube Runner with the -e switch.
ERROR: Re-run SonarQube Runner using the -X switch to enable full debug logging.
Build step 'Invoke Standalone Sonar Analysis' marked build as failure
Finished: FAILUR
I enabled Visual Studio Bootstrapper on SonarQube, and I ran SonarQube Runner again, then I got following error.
ERROR: Error during Sonar runner execution
ERROR: Unable to execute Sonar
ERROR: Caused by: java.io.IOException: Cannot run program "C:/Program Files (x86)/Microsoft Visual Studio 12.0/Team Tools/Static Analysis Tools/FxCop/FxCopCmd.exe": CreateProcess error=2, ?w?????t?#?
ERROR: Caused by: Cannot run program "C:/Program Files (x86)/Microsoft Visual Studio 12.0/Team Tools/Static Analysis Tools/FxCop/FxCopCmd.exe": CreateProcess error=2, ?w?????t?#?
ERROR: Caused by: CreateProcess error=2, ?w?????t?#?
ERROR:
ERROR: To see the full stack trace of the errors, re-run SonarQube Runner with the -e switch.
ERROR: Re-run SonarQube Runner using the -X switch to enable full debug logging.
I add "sonar.fxcop.installDirector=C:/Program Files (x86)/Microsoft FxCop 1.35" to sonar-project.properties, and ran SonarQube Runner again however same error occured.
I guess if Visual Studio Bootstrapper disabled and sonar-project.properties specify "sonar.cs.fxcop.assembly" and "sonar.fxcop.installDirector" correctly, It's work fine, but I don't want to specify many properties in sonar-project.properties.
How can I set FxCop execution path with enabling Visual Studio Bootstrapper?
Environment:
SonarQube4.2
SonarQube's C# plugin 3.0
SonarQube Runner 2.4
sonar-project.properties
sonar.projectKey=xxxxx
sonar.projectVersion=1.0
sonar.projectName=Project Name
sonar.language=cs
sonar.dotnet.key.generation.strategy=safe
sonar.sourceEncoding=UTF-8
# This property is set because it is required by the SonarQube Runner.
# But it is not taken into account because the location of the source
# code is retrieved from the .sln and .csproj files.
sonar.sources=.
sonar.fxcop.mode=skip
sonar.gendarme.mode=skip
sonar.gallio.mode=skip
sonar.ndeps.mode=skip
sonar.stylecop.mode=skip
sonar.fxcop.installDirector=C:/Program Files (x86)/Microsoft FxCop 1.35
Regards
I found the solution for this issue , Login as an administration on sonar qube and then go to setting , under general setting you find Category, select C# then Click on Code Analysis/FxCop tab , then find "Path to FxCopCMD.Exe" and add the full path of FXCopCMD.exe as suggested in example
click on this to see image and process
Same problem here. I think after you installed Visual Studio Bootstrapper you'll need to setup the following key to match the path to FxCop executable:
sonar.cs.fxcop.fxCopCmdPath
which by default has the value you mentioned in the second error log.

build .net application in Jenkins using MSBuild

I have a .net application built on .net framework 3.5, I am trying to build this application on Jenkins CI server. I've added MSBuild plugin and and have added path to the .exe file of 2.0, 3.5 and 4.0 versions of MSBuild. But my building processes are failing by showing the below error message.
Path To MSBuild.exe: msbuild.exe
Executing command: cmd.exe /C msbuild.exe Neo.sln && exit %%ERRORLEVEL%%
[Test project] $ cmd.exe /C msbuild.exe Neo.sln && exit %%ERRORLEVEL%%
'msbuild.exe' is not recognized as an internal or external command,
operable program or batch file.
Build step 'Build a Visual Studio project or solution using MSBuild.' marked uild as failure
Finished: FAILURE
Could anyone plz help me out..??
To make the MSBuild plugin work, you need to configure the plugin in the Jenkins management screen.
NOTE: in the newer Jenkins versions you find the MSBuild configuration in the Global Tool Configuration:
Note the "Name" field, where I've called this particular configuration v4.0.30319. You could call it anything you like, but ideally the name will somehow refer to the version.
You'll need to refer to this name later in the Jenkins PROJECT that's failing.
Note: The yellow warning implies that the Path to MSBuild field should be populated with a directory name rather than a file name. In practice you do need to enter the filename here too (ie. msbuild.exe) or the build step will fail.
In the Jenkins project that's failing, go to the MSBuild build step.
The first field in the build step is "MSBuild Version". If you created the build step before configuring any MSBuild versions, the value here will be (default).
After configuring one or more MSBuild versions, the drop down will be populated with the available configurations. Select the one you require.
You can see here that I've now selected the named configuration that matches the installation above.
Jenkins | Manage Jenkins | Configure System
scroll down to the MSBuild section and click MSBuild installations
define the full path to msbuild.exe, on my system I have 3.5 and v4.0.30319
Note - specify the path to 32-bit tools even on a 64-bit system, otherwise you might get an error message:
Building Windows Phone application using MSBuild 64 bit is not supported.
So in Jenkins - it could be for example:
Name: Version 3.5
Path: C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe
Name: Version 4.0
Path: C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSbuild.exe
I think you should set an absolute path for "msbuild.exe" in your Jenkins configuration,
for example:
C:\Windows\Microsoft.NET\Framework\v3.5\msbuild.exe
You can also add the path where the msbuild.exe is, to the PATH system environment variable of the node (or nodes) that is running that specific job.
You could try executing the
%comspec% /k ""c:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"" x86
command, which will temporarily update your environment path variables to reflect the VS2010 build environment. Execute this before you call MSBUILD and see what happens. I use this in my own build scripts with no issues.
Side note; it's very likely counterproductive to have multiple versions of MSBUILD on your PATH. Concentrate on getting one version working and go from there.

Categories