In short
I have written custom XPATH xml rules to detect problems with the nuget.config and csproj, i have confirmed the rules work when not using scannerMode MSBuild. However, trying combine MSBuild to detect c# problems with xml rules seems damn freaking hard…
The fact that i cant easily setup a scan of a folder structure containing c# and other non-c# files, but are instead forced into this idea that when your scanning a .net project you can only scan the content of the csproj-projects folders is annoying at best.
I have a folder structure like this
Source
InternalApi
nuget.config <- Is scanned, but only added it for testing
InternalApi.csproj <- Not scanned
nuget.config <- Not scanned
We are using Azure DevOps pipelines
- task: SonarQubePrepare@5
displayName: Sonarqube prepare
inputs:
SonarQube: $(sonarqube_service_connection)
scannerMode: 'MSBuild'
projectKey: $(sonarqube_projectKey)
projectName: $(sonarqube_projectName)
cliSources: '$(Build.SourcesDirectory)'
extraProperties: |
sonar.cs.vscoveragexml.reportsPaths=$(coverage_file_path)
sonar.log.level=DEBUG
sonar.projectBaseDir=$(Build.SourcesDirectory)
- task: DotNetCoreCLI@2
displayName: 'dotnet build'
inputs:
command: build
projects: '$(path_to_solution)'
arguments: --configuration $(BuildConfiguration) --no-restore
- task: SonarQubeAnalyze@5
displayName: Sonarqube analyze
Stripped InternalApi.csproj file
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<SQAdditionalAnalysisFileItemTypes>config;csproj</SQAdditionalAnalysisFileItemTypes>
</PropertyGroup>
</Project>
I have tried to run two separate analyze jobs, but the last analyze overwrite the first. Which in effect deletes comments on the Azure DevOps PR.
I struggle with
- Detect the csproj file within the project
- Detect the nuget.config file outside the project structure
- Run two separate scans and combine the result
Extra info
- which versions are you using: 9.9.1.69595
- how is SonarQube deployed: Helm
Relevant logs from azure devops pipeline step
Starting: Sonarqube prepare
==============================================================================
Task : Prepare Analysis Configuration
Description : Prepare SonarQube analysis configuration
Version : 5.19.1
Author : sonarsource
Help : Version: 5.19.1. [More Information](http://redirect.sonarsource.com/doc/install-configure-scanner-tfs-ts.html)
==============================================================================
/usr/bin/dotnet /agent/_work/_tasks/SonarQubePrepare_15b84ca1-b62f-4a2a-a403-89b77a063157/5.19.1/dotnet-sonar-scanner-msbuild/SonarScanner.MSBuild.dll begin /k:SystemInfo
SonarScanner for MSBuild 5.15
Using the .NET Core version of the Scanner for MSBuild
Pre-processing started.
Preparing working directories...
13:27:43.079 Updating build integration targets...
13:27:43.842 Fetching analysis configuration settings...
13:27:44.203 Provisioning analyzer assemblies for cs...
13:27:44.204 Installing required Roslyn analyzers...
13:27:44.205 Processing plugin: csharp version 8.51.0.59060
13:27:44.788 Processing plugin: vbnet version 8.51.0.59060
13:27:44.84 Processing plugin: securitycsharpfrontend version 9.9.0.19083
13:27:45.024 Provisioning analyzer assemblies for vbnet...
13:27:45.024 Installing required Roslyn analyzers...
13:27:45.024 Processing plugin: csharp version 8.51.0.59060
13:27:45.025 Processing plugin: vbnet version 8.51.0.59060
13:27:45.109 Downloading cache. Project key: SystemInfo, branch: master.
13:27:45.148 Incremental PR analysis: 0 files out of 150 are unchanged.
13:27:45.207 Pre-processing succeeded.
Finishing: Sonarqube prepare
Starting: Sonarqube analyze
==============================================================================
Task : Run Code Analysis
Description : Run scanner and upload the results to the SonarQube server.
14:05:59.779 The exclude flag has been set so the project will not be analyzed. Project file: /agent/_work/12/s/Source/Sec_SystemInfo.Migrations/Sec_SystemInfo.Migrations.csproj
14:05:59.786 Using longest common projects path as a base directory: '/agent/_work/12/s/Source'.
14:05:59.81 File was referenced by the following projects: '/agent/_work/12/s/Source/InternalMessaging.Batch.Tests/InternalMessaging.Batch.Tests.csproj', '/agent/_work/12/s/Source/InternalApi.Tests/InternalApi.Tests.csproj', '/agent/_work/12/s/Source/Logic.Tests/Logic.Tests.csproj'.
14:05:59.821 Dumping content of sonar-project.properties
------------------------------------------------------------------------
sonar.projectKey=SystemInfo
sonar.working.directory=/agent/_work/12/.sonarqube/out/.sonar
sonar.projectBaseDir=/agent/_work/12/s/Source
sonar.pullrequest.cache.basepath=/agent/_work/12/s
0E72F32E-300D-4A69-839E-6FEED8453AB0.sonar.projectKey=SystemInfo:0E72F32E-300D-4A69-839E-6FEED8453AB0
0E72F32E-300D-4A69-839E-6FEED8453AB0.sonar.projectName=InternalApi
0E72F32E-300D-4A69-839E-6FEED8453AB0.sonar.projectBaseDir=/agent/_work/12/s/Source/InternalApi
0E72F32E-300D-4A69-839E-6FEED8453AB0.sonar.sourceEncoding=utf-8
0E72F32E-300D-4A69-839E-6FEED8453AB0.sonar.sources=\
"/agent/_work/12/s/Source/InternalApi/Controllers/v1/ApisController.cs",\
"/agent/_work/12/s/Source/InternalApi/Controllers/v1/ApplicationInstancesController.cs",\
"/agent/_work/12/s/Source/InternalApi/Controllers/v1/ApplicationsController.cs",\
"/agent/_work/12/s/Source/InternalApi/Controllers/v1/ErrorCodesController.cs",\
"/agent/_work/12/s/Source/InternalApi/Controllers/v1/LibrariesController.cs",\
"/agent/_work/12/s/Source/InternalApi/Controllers/v1/MessageTypesController.cs",\
"/agent/_work/12/s/Source/InternalApi/Controllers/v1/TestController.cs",\
"/agent/_work/12/s/Source/InternalApi/Program.cs",\
"/agent/_work/12/s/Source/InternalApi/Startup.cs",\
"/agent/_work/12/s/Source/InternalApi/obj/Release/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs",\
"/agent/_work/12/s/Source/InternalApi/obj/Release/InternalApi.AssemblyInfo.cs",\
"/agent/_work/12/s/Source/InternalApi/obj/Release/Helsenorge.SystemInfo.InternalApi.MvcApplicationPartsAssemblyInfo.cs",\
"/agent/_work/12/s/Source/InternalApi/nuget.config",\
"/agent/_work/12/s/Source/InternalApi/web.config",\
"/agent/_work/12/s/Source/InternalApi/Config/InternalApi.Config.dev-mot-k8s.vm.json",\
"/agent/_work/12/s/Source/InternalApi/Config/InternalApi.Config.dev.vm.json",\
"/agent/_work/12/s/Source/InternalApi/Config/InternalApi.Config.json",\
"/agent/_work/12/s/Source/InternalApi/Config/InternalApi.Config.vm.json",\
"/agent/_work/12/s/Source/InternalApi/Dockerfile",\
"/agent/_work/12/s/Source/InternalApi/InternalApi.Octopus.nuspec",\
"/agent/_work/12/s/Source/InternalApi/Properties/launchSettings.json",\
"/agent/_work/12/s/Source/InternalApi/obj/Release/apphost"