dotnet core sonarscanner not accepting arguments - sonarqube

I'm really not sure what's going on here.
I've got 2 issues.
SonarScanner is not accepting arguments that it tells me I can use
SonarScanner is not recognising my properties file.
What I did:
First I installed the scanner dotnet tool install --global dotnet-sonarscanner
Then I tried to run dotnet sonarscanner begin /key:"mykey" /s:"./sonar-project.properties" which gave me the following error message:
SonarScanner for MSBuild 4.6
Using the .NET Core version of the Scanner for MSBuild
Loading analysis properties from path\sonar-project.properties
Unable to read the SonarQube analysis settings file 'path\sonar-project.properties'. Please fix the content of this file.
Not sure why that is because I copied my file from here.
I then do dotnet scanner being /key:"mykey" /? and it tells me I can use /d:sonar.verbose=true. I immediatey try this command dotnet sonarscanner being /key:"mykey" /d:sonar.verbose=true and am met with this error message.
22:39:19.402 22:39:19.399 Unrecognized command line argument: being
22:39:19.403 22:39:19.4 Unrecognized command line argument: d:sonar.verbose=true
22:39:19.404 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.
22:39:19.405 Pre-processing failed. Exit code: 1
I also try dotnet sonarscanner begin /key:"mykey" /d:sonar.host.url="https://sonar.qube" but it's the same thing, it cannot recognise the argument.
Any ideas are welcome.
My sonar-project.properties
sonar.login=token
sonar.host=https://sonar.qube
sonar.projectKey=mykey
sonar.projectName=mykey
sonar.sourceEncoding=UTF-8

You have to change the '/k' for '-k'
dotnet sonarscanner begin -k:"proj_key" -d:sonar.host.url="http://myurl"

If your problem still exists, can you share the properties file? I think you have the Java project file, and not the MSBuild file (which is an XML file, see: https://docs.sonarqube.org/display/SCAN/Additional+Analysis+Parameters).
<?xml version="1.0" encoding="utf-8" ?>
<SonarQubeAnalysisProperties
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.sonarsource.com/msbuild/integration/2015/1">
<Property Name="sonar.verbose">true</Property>
</SonarQubeAnalysisProperties>
The example you link towards, is showing Java code and settings.
In the second issue you have, there is a typo:
dotnet sonarscanner being /key:"mykey" /d:sonar.verbose=true
should be
dotnet sonarscanner begin /key:"mykey" /d:sonar.verbose=true
Although i expect there was a second typo for the verbosity, looking at your console output. So, your command does not seem to reflect the output there.
For the final example you give, sonar is complaining about the URL, but other than that, the command line arguments are correct and working on my machine.

Related

How to run visual studio build in azure devops

I want to build my solution file in azure devops. I have added this to build pipeline, I see this step doesn't succeed. It tells " MSBUILD : error MSB1008: Only one project can be specified." I suspect I am making some mistake in specifyning
msbuild args
msbuild $(Build.SourcesDirectory)\ansysfnonet\ansysfnonet.vs2017.sln /t:$(Build.SourcesDirectory)\ansysfnonet\ansysfnonet.csproj:Rebuild;
I tried specify only proj file as msbuild arg it didn't work for me
I tried without specifying msbuild it throws me whole lot of errors.
Someone please help me , why I am failing in this step and how to solve this error.
Thanks
You don't need to specify an msbuild command line in the MSBuild Arguments field. You need to specify any additional MSBuild parameters beyond the defaults.
Clear that field. That should fix the problem you're encountering.

SonarQube Scanner for MSBuild on macOS using mono

I'm trying to use SonarQube Scanner for MSBuild on a Xamarin project on macOS using mono. As MSBuild 15.0 is now shipped with Xamarin, I figured this could actually work.
I can successfully run the scanner's "begin" using mono like so:
mono sonar-scanner-msbuild-2/SonarQube.Scanner.MSBuild.exe begin /k:"KEY"
The command creates the following files:
.sonarqube/conf/SonarQubeAnalysisConfig.xml
.sonarqube/conf/SonarQubeRoslyn-cs.ruleset
.sonarqube/conf/cs/SonarLint.xml
Before running MSBuild, I've added the following import to the csproj files of my solution:
<Import Project="/Users/someuser/.local/share/Microsoft/MSBuild/14.0/Microsoft.Common.targets/ImportBefore/SonarQube.Integration.ImportBefore.targets" />
I'm running MSBuild using:
msbuild /t:Rebuild
Now the build starts correctly but eventually terminates with two errors:
"/Users/someuser/Project/Project.sln" (Rebuild target) (1) ->
"/Users/someuser/Project/Project.UI.iOS/Project.UI.iOS.csproj" (Rebuild target) (2) ->
"/Users/someuser/Project/Project.Core/Project.Core.csproj" (default target) (3:3) ->
(CoreCompile target) ->
CSC : error CS2001: Source file `/additionalfile:/Users/someuser/Project/.sonarqube/conf/cs/SonarLint.xml' could not be found [/Users/someuser/Project/Project.Core/Project.Core.csproj]
CSC : error CS2001: Source file `/additionalfile:/Users/someuser/Project/.sonarqube/conf/Project.Core_AnyCPU_Debug_1267/ProjectOutFolderPath.txt' could not be found [/Users/someuser/Project/Project.Core/Project.Core.csproj]
Both files do exist in the filesystem, the first file was created in the scanner's begin invocation and the second file was created during the MSBuild execution.
Why would MSBuild not be able to find / access these two files? Is there anything that can be done about it?
After checking with the folks taking care of MSBuild, the solution has been provided in this Github issue thread:
To quote radical's comment from the Github issue:
You could try building with csc by passing /p:CscToolExe=csc.exe /p:CscToolPath=/Library/Frameworks/Mono.framework/Versions/4.8.0/lib/mono/msbuild/15.0/bin/Roslyn/ to msbuild
Unfortunately, even though MSBuild works with the above adjustments, SonarQube fails afterwards. I will follow up with the SonarQube people to see whether this can be worked around.

SonarQube Scanner for MSBuild doesn't run

I am using Jenkins to run SonarQube for my .Net project(C#).
Visual Studio:2015
MsBuils: 14
Jenkins on Linux (1.624)
SonarServer on Linux (Sonar Version 6.0)
Job Config:
SonarQube Scanner for MsBuilds- Begin analysis
Project key:
Project Name:
Proj Version:
Build a Visual Studio Project or Solution using MSBuild:
MsBuild Version : MsBuild 4.6
MsBuild File: CI.Sln
Command Line Arguments: /p:Configuration=Release /target:Build
SonarQube Scanner for MSBuild- End Analysis
I can generate report for Visual Studio 2015 and post to Sonar Server but when i try to run in Jenkins job its doesn't work.
Error:
ERROR: JAVA_HOME exists but does not point to a valid Java home folder. No "\bin\java.exe" file can be found there.
The SonarQube Scanner did not complete successfully
08:42:40.676 Creating a summary markdown file...
Post-processing failed. Exit code: 1
ERROR: Execution of SonarQube Scanner for MSBuild failed (exit code 1)
I have Windows Server as an agent and out put of Microsoft Windows [Version 6.2.9200]
C:\Windows\System32>echo %JAVA_HOME%
C:\Program Files\Java\jre8
Java Home Variable Path:C:\Program Files\Java\jre8
Please let me know how would I make jenkins job work.
This was a rookie mistake.
This was an issue related to JDK, as i installed JRE but not JDK. I have installed JDK and add the path to Jenkins master and Jenkins job. Ran the job and horraaayyyy, Its working now.

Publish VS2010 Solution to ISS(local) using Jenkins MSBuild Plugin command line

Jenkins successfully build my job using MSBuild plugin(framework 4.0) with this Command Line Arguments
/p:Configuration=Debug /p:Platform="Any CPU" /p:PackageTempDir=C:\inetpub\wwwroot\Example_Jenkins
The problem is that the solution isn't published in the given directory(C:\inetpub\wwwroot\Example_Jenkins) it only goes in the jenkins workspace folder. I even tried changing the command line arguments to commands like in web publish still files are not being deployed in the given folder.
You doing it not in the correct way. The correct way is described, for example, here: http://www.digitallycreated.net/Blog/59/locally-publishing-a-vs2010-asp.net-web-application-using-msbuild
msbuild Website.csproj "/p:Platform=AnyCPU;Configuration=Debug;PublishDestination=C:\inetpub\wwwroot\Example_Jenkins" /t:PublishToFileSystem
PS I don't think it's so much jenkins related :)

How do I configure visual studio to run xUnit.net tests?

I have configured Visual Studio 2010 to debug xUnit.net tests by setting the Project Settings | Debug | Start External Program to run the xUnit.net console runner.
This works OK but only when providing the complete path to the test project dll via the Command Line Arguments eg: "c:\development\TestProject.dll"
I have tried using $(BinDir)$(TargetName)$(TargetExt) as parameters via the Command Line Arguements section but it does not work. Any suggests on how I can avoid the explicit/full path?
This is what I use in my .csproj file to run the xUnit GUI runner as the start action:
<PropertyGroup>
<StartAction>Program</StartAction>
<StartProgram>$(MSBuildProjectDirectory)\..\..\Packages\xunit.runners.1.9.1\tools\xunit.gui.clr4.exe</StartProgram>
<StartArguments>"$(MSBuildProjectDirectory)\$(OutPutPath)$(AssemblyName).dll"</StartArguments>
</PropertyGroup>
For this to work, all you have to do is install the xUnit.net Runners NuGet package:
PM> Install-Package xunit.runners
The only downside so far, is that it's version specific, so every time you update the NuGet package to latest, you should update this configuration to point to the correct runner.
This answer was given before James' and Brad's awesome work with xUnit.net Runners. See michielvoo's answer below.
To avoid the problem of explicitly giving the library name one can use cmd.exe with command line arguements: /C xunit.console.exe $(BinDir)$(TargetName)$(TargetExt)
Check Use Output Window
Use the Tools|Options|Keyboard configuration to assign a hot key.
A alternative route is use a VS plugin as testrunner. For instance ReSharper.
I simply type the full name of the assembly thats all.
Under command line arguments: SharedDataBridge.Tests.dll

Resources