I’m trying to run SonarScanner .NET. I’d like to keep most of the fixed analysis parameters in the config file rather than building huge CLI command each time. I’m not finding the documentation very clear on how to that. I’ve seen this example:
<!-- in .csproj -->
<ItemGroup>
<SonarQubeSetting Include="sonar.stylecop.projectFilePath">
<Value>$(MSBuildProjectFullPath)</Value>
</SonarQubeSetting>
</ItemGroup>
so I tried to replicate it:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
...
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NLog" Version="4.7.14"/>
...
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\lib\<local-dependency>.csproj" />
</ItemGroup>
<ItemGroup>
<SonarQubeSetting Include="sonar.projectKey">
<Value>myorg_myproj</Value>
</SonarQubeSetting>
<SonarQubeSetting Include="sonar.organization">
<Value>myorg</Value>
</SonarQubeSetting>
<SonarQubeSetting Include="sonar.host.url">
<Value>https://sonarcloud.io</Value>
</SonarQubeSetting>
<SonarQubeSetting Include="sonar.projectName">
<Value>myproj</Value>
</SonarQubeSetting>
<SonarQubeSetting Include="sonar.sources">
<Value>src/</Value>
</SonarQubeSetting>
<SonarQubeSetting Include="sonar.exclusions">
<Value>**/*.json, **/*.py, **/*.js, **/*.xml, **/*.html, **/*.yml, **/*.yaml</Value>
</SonarQubeSetting>
<SonarQubeSetting Include="sonar.tests">
<Value>test/</Value>
</SonarQubeSetting>
<SonarQubeSetting Include="sonar.cs.vscoveragexml.reportsPaths">
<Value>dist/coverage.xml</Value>
</SonarQubeSetting>
</ItemGroup>
</Project>
Yet when I run /root/.dotnet/tools/dotnet-sonarscanner begin
I get the following output:
SonarScanner for MSBuild 6.2
Using the .NET Core version of the Scanner for MSBuild
Pre-processing started.
Preparing working directories...
07:59:34.867 07:59:34.865 A required argument is missing: /key:[SonarQube/SonarCloud project key]
07:59:34.867 Expecting at least the following command line argument:
- SonarQube/SonarCloud project key
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.
07:59:34.867 Pre-processing failed. Exit code: 1
What am I missing?