Problem analysing with Scanner for MSBuild

Hello,

I have the same problem, and I try to solve it but I didn’t find a solution, someone have explication?

Information:
I got this package https://github.com/SonarSource/sonar-scanner-msbuild/releases/download/4.7.1.2311/sonar-scanner-msbuild-4.7.1.2311-netcoreapp2.0.zip from https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-msbuild/
And I followed all instructions, and change some things but don’t works.
I’m running this on gitlab with image: mcr.microsoft.com/dotnet/core/sdk:3.0-alpine3.9


$ chmod +x ./install-sonar
$ PATH=$PATH:`pwd`/install-sonar
$ dotnet ./install-sonar/SonarScanner.MSBuild.dll begin /k:"dot-hello" /d:sonar.verbose=true
SonarScanner for MSBuild 4.7.1
Using the .NET Core version of the Scanner for MSBuild
Default properties file was found at /builds/toto/obs-ci-dotnet/install-sonar/SonarQube.Analysis.xml
Loading analysis properties from /builds/toto/obs-ci-dotnet/install-sonar/SonarQube.Analysis.xml
sonar.verbose=true was specified - setting the log verbosity to 'Debug'
Pre-processing started.
Preparing working directories...
Using environment variables to determine the download directory...
11:32:21.307  11:32:21.299  Loading analysis properties from /builds/toto/obs-ci-dotnet/install-sonar/SonarQube.Analysis.xml
11:32:21.307  11:32:21.307  sonar.verbose=true was specified - setting the log verbosity to 'Debug'
11:32:21.309  Updating build integration targets...
11:32:21.316  Installed SonarQube.Integration.ImportBefore.targets to /root/.local/share/Microsoft/MSBuild/4.0/Microsoft.Common.targets/ImportBefore
11:32:21.316  Installed SonarQube.Integration.ImportBefore.targets to /root/.local/share/Microsoft/MSBuild/10.0/Microsoft.Common.targets/ImportBefore
11:32:21.317  Installed SonarQube.Integration.ImportBefore.targets to /root/.local/share/Microsoft/MSBuild/11.0/Microsoft.Common.targets/ImportBefore
11:32:21.317  Installed SonarQube.Integration.ImportBefore.targets to /root/.local/share/Microsoft/MSBuild/12.0/Microsoft.Common.targets/ImportBefore
11:32:21.317  Installed SonarQube.Integration.ImportBefore.targets to /root/.local/share/Microsoft/MSBuild/14.0/Microsoft.Common.targets/ImportBefore
11:32:21.317  Installed SonarQube.Integration.ImportBefore.targets to /root/.local/share/Microsoft/MSBuild/15.0/Microsoft.Common.targets/ImportBefore
11:32:21.318  Installed SonarQube.Integration.ImportBefore.targets to /root/.local/share/Microsoft/MSBuild/Current/Microsoft.Common.targets/ImportBefore
11:32:21.318  Installed SonarQube.Integration.ImportBefore.targets to /root/Microsoft/MSBuild/15.0/Microsoft.Common.targets/ImportBefore
11:32:21.318  Installed SonarQube.Integration.ImportBefore.targets to /root/Microsoft/MSBuild/Current/Microsoft.Common.targets/ImportBefore
11:32:21.319  Installed SonarQube.Integration.targets to /builds/toto/obs-ci-dotnet/.sonarqube/bin/targets
11:32:21.32  Creating config and output folders...
11:32:21.321  Creating directory: /builds/toto/obs-ci-dotnet/.sonarqube/conf
11:32:21.321  Creating directory: /builds/toto/obs-ci-dotnet/.sonarqube/out
11:32:21.365  Fetching analysis configuration settings...
11:32:21.366  Downloading from 'begin_of_url'10.0.0.1/api/server/version...
11:32:21.534  Fetching properties for project 'dot-hello' from 'begin_of_url'10.0.0.1/api/settings/values?component=dot-hello...
11:32:21.534  Downloading from 'begin_of_url'10.0.0.1/api/settings/values?component=dot-hello...
11:32:21.699  Downloading from 'begin_of_url'10.0.0.1/api/languages/list...
11:32:21.719  Fetching quality profile for project 'dot-hello' from 'begin_of_url'10.0.0.1/api/qualityprofiles/search?projectKey=dot-hello...
11:32:21.72  Downloading from 'begin_of_url'10.0.0.1/api/qualityprofiles/search?projectKey=dot-hello...
11:32:21.756  Fetching active rules for quality profile 'AW3U9Y7NTrH1UpIec8Sj' from 'begin_of_url'10.0.0.1/api/rules/search?f=repo,name,severity,lang,internalKey,templateKey,params,actives&ps=500&activation=true&qprofile=AW3U9Y7NTrH1UpIec8Sj&p=1...
11:32:21.757  Downloading from 'begin_of_url'10.0.0.1/api/rules/search?f=repo,name,severity,lang,internalKey,templateKey,params,actives&ps=500&activation=true&qprofile=AW3U9Y7NTrH1UpIec8Sj&p=1...
11:32:21.846  Fetching rules not active in quality profile 'AW3U9Y7NTrH1UpIec8Sj' for language 'cs' from 'begin_of_url'10.0.0.1/api/rules/search?f=repo,name,severity,lang,internalKey,templateKey,params&ps=500&activation=false&qprofile=AW3U9Y7NTrH1UpIec8Sj&p=1&languages=cs...
11:32:21.847  Downloading from 'begin_of_url'10.0.0.1/api/rules/search?f=repo,name,severity,lang,internalKey,templateKey,params&ps=500&activation=false&qprofile=AW3U9Y7NTrH1UpIec8Sj&p=1&languages=cs...
11:32:21.892  Local analyzer cache: /tmp/.sonarqube/resources
11:32:21.904  Writing Roslyn generated ruleset to /builds/toto/obs-ci-dotnet/.sonarqube/conf/SonarQubeRoslyn-cs.ruleset...
11:32:21.922  Writing Roslyn generated ruleset to /builds/toto/obs-ci-dotnet/.sonarqube/conf/SonarQubeRoslyn-cs-test.ruleset...
11:32:21.926  Provisioning analyzer assemblies for cs...
11:32:21.927  Installing required Roslyn analyzers...
11:32:21.928  Processing plugin: csharp version 7.15.0.8572
11:32:22.024  Cache miss: plugin files were not found in the local cache
11:32:22.03  Fetching resource for plugin: csharp, version 7.15.0.8572. Resource: SonarAnalyzer-7.15.0.8572.zip
11:32:22.031  Downloading SonarAnalyzer-7.15.0.8572.zip from 'begin_of_url'10.0.0.1/static/csharp/SonarAnalyzer-7.15.0.8572.zip to /tmp/.sonarqube/resources/0
11:32:22.031  Downloading file from 'begin_of_url'10.0.0.1/static/csharp/SonarAnalyzer-7.15.0.8572.zip to /tmp/.sonarqube/resources/0/SonarAnalyzer-7.15.0.8572.zip...
11:32:22.101  Extracting files to /tmp/.sonarqube/resources/0...
11:32:22.141  Processing plugin: vbnet version 7.15.0.8572
11:32:22.161  Cache miss: plugin files were not found in the local cache
11:32:22.161  Fetching resource for plugin: vbnet, version 7.15.0.8572. Resource: SonarAnalyzer-7.15.0.8572.zip
11:32:22.161  Downloading SonarAnalyzer-7.15.0.8572.zip from 'begin_of_url'10.0.0.1/static/vbnet/SonarAnalyzer-7.15.0.8572.zip to /tmp/.sonarqube/resources/1
11:32:22.161  Downloading file from 'begin_of_url'10.0.0.1/static/vbnet/SonarAnalyzer-7.15.0.8572.zip to /tmp/.sonarqube/resources/1/SonarAnalyzer-7.15.0.8572.zip...
11:32:22.216  Extracting files to /tmp/.sonarqube/resources/1...
11:32:22.232  Writing Roslyn analyzer additional file to /builds/toto/obs-ci-dotnet/.sonarqube/conf/cs/SonarLint.xml...
11:32:22.233  Fetching quality profile for project 'dot-hello' from 'begin_of_url'10.0.0.1/api/qualityprofiles/search?projectKey=dot-hello...
11:32:22.233  Downloading from 'begin_of_url'10.0.0.1/api/qualityprofiles/search?projectKey=dot-hello...
11:32:22.264  Fetching active rules for quality profile 'AW3U9ZUeTrH1UpIec8qn' from 'begin_of_url'10.0.0.1/api/rules/search?f=repo,name,severity,lang,internalKey,templateKey,params,actives&ps=500&activation=true&qprofile=AW3U9ZUeTrH1UpIec8qn&p=1...
11:32:22.264  Downloading from 'begin_of_url'10.0.0.1/api/rules/search?f=repo,name,severity,lang,internalKey,templateKey,params,actives&ps=500&activation=true&qprofile=AW3U9ZUeTrH1UpIec8qn&p=1...
11:32:22.308  Fetching rules not active in quality profile 'AW3U9ZUeTrH1UpIec8qn' for language 'vbnet' from 'begin_of_url'10.0.0.1/api/rules/search?f=repo,name,severity,lang,internalKey,templateKey,params&ps=500&activation=false&qprofile=AW3U9ZUeTrH1UpIec8qn&p=1&languages=vbnet...
11:32:22.308  Downloading from 'begin_of_url'10.0.0.1/api/rules/search?f=repo,name,severity,lang,internalKey,templateKey,params&ps=500&activation=false&qprofile=AW3U9ZUeTrH1UpIec8qn&p=1&languages=vbnet...
11:32:22.334  Local analyzer cache: /tmp/.sonarqube/resources
11:32:22.335  Writing Roslyn generated ruleset to /builds/toto/obs-ci-dotnet/.sonarqube/conf/SonarQubeRoslyn-vbnet.ruleset...
11:32:22.336  Writing Roslyn generated ruleset to /builds/toto/obs-ci-dotnet/.sonarqube/conf/SonarQubeRoslyn-vbnet-test.ruleset...
11:32:22.336  Provisioning analyzer assemblies for vbnet...
11:32:22.336  Installing required Roslyn analyzers...
11:32:22.336  Processing plugin: csharp version 7.15.0.8572
11:32:22.337  Cache hit: using plugin files from /tmp/.sonarqube/resources/0
11:32:22.337  Processing plugin: vbnet version 7.15.0.8572
11:32:22.338  Cache hit: using plugin files from /tmp/.sonarqube/resources/1
11:32:22.339  Writing Roslyn analyzer additional file to /builds/toto/obs-ci-dotnet/.sonarqube/conf/vbnet/SonarLint.xml...
11:32:22.378  Pre-processing succeeded.
$ dotnet build dot-hello.sln
Microsoft (R) Build Engine version 16.3.2+e481bbf88 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 106.06 ms for /builds/toto/obs-ci-dotnet/myWebApp/myWebApp.csproj.
  Build selected

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:01.25

$ dotnet ./install-sonar/SonarScanner.MSBuild.dll end
SonarScanner for MSBuild 4.7.1
Using the .NET Core version of the Scanner for MSBuild
Post-processing started.
11:32:25.234  11:32:25.229  Uninstalling target: /root/.local/share/Microsoft/MSBuild/4.0/Microsoft.Common.targets/ImportBefore\SonarQube.Integration.ImportBefore.targets
11:32:25.234  11:32:25.23  Uninstalling target: /root/.local/share/Microsoft/MSBuild/10.0/Microsoft.Common.targets/ImportBefore\SonarQube.Integration.ImportBefore.targets
11:32:25.234  11:32:25.231  Uninstalling target: /root/.local/share/Microsoft/MSBuild/11.0/Microsoft.Common.targets/ImportBefore\SonarQube.Integration.ImportBefore.targets
11:32:25.234  11:32:25.231  Uninstalling target: /root/.local/share/Microsoft/MSBuild/12.0/Microsoft.Common.targets/ImportBefore\SonarQube.Integration.ImportBefore.targets
11:32:25.234  11:32:25.231  Uninstalling target: /root/.local/share/Microsoft/MSBuild/14.0/Microsoft.Common.targets/ImportBefore\SonarQube.Integration.ImportBefore.targets
11:32:25.234  11:32:25.231  Uninstalling target: /root/.local/share/Microsoft/MSBuild/15.0/Microsoft.Common.targets/ImportBefore\SonarQube.Integration.ImportBefore.targets
11:32:25.234  11:32:25.231  Uninstalling target: /root/.local/share/Microsoft/MSBuild/Current/Microsoft.Common.targets/ImportBefore\SonarQube.Integration.ImportBefore.targets
11:32:25.234  11:32:25.231  Uninstalling target: /root/Microsoft/MSBuild/15.0/Microsoft.Common.targets/ImportBefore\SonarQube.Integration.ImportBefore.targets
11:32:25.234  11:32:25.231  Uninstalling target: /root/Microsoft/MSBuild/Current/Microsoft.Common.targets/ImportBefore\SonarQube.Integration.ImportBefore.targets
11:32:25.234  11:32:25.234  sonar.verbose=true was specified - setting the log verbosity to 'Debug'
11:32:25.235  Loading the SonarQube analysis config from /builds/toto/obs-ci-dotnet/.sonarqube/conf/SonarQubeAnalysisConfig.xml
11:32:25.235  Not running under TeamBuild
11:32:25.235  Analysis base directory: /builds/toto/obs-ci-dotnet/.sonarqube
Build directory: 
Bin directory: /builds/toto/obs-ci-dotnet/.sonarqube/bin
Config directory: /builds/toto/obs-ci-dotnet/.sonarqube/conf
Output directory: /builds/toto/obs-ci-dotnet/.sonarqube/out
Config file: /builds/toto/obs-ci-dotnet/.sonarqube/conf/SonarQubeAnalysisConfig.xml
Generating SonarQube project properties file to /builds/toto/obs-ci-dotnet/.sonarqube/out/sonar-project.properties
The SonarQube MSBuild integration failed: SonarQube was unable to collect the required information about your projects.
Possible causes:
  1. The project has not been built - the project must be built in between the begin and end steps
  2. An unsupported version of MSBuild has been used to build the project. Currently MSBuild 14.0.25420.1 and higher are supported.
  3. The begin, build and end steps have not all been launched from the same folder
  4. None of the analyzed projects have a valid ProjectGuid and you have not used a solution (.sln)
Writing processing summary to /builds/toto/obs-ci-dotnet/.sonarqube/out/ProjectInfo.log
Generation of the sonar-properties file failed. Unable to complete SonarQube analysis.
11:32:25.254  Post-processing failed. Exit code: 1
Running after script...
$ cat /builds/toto/obs-ci-dotnet/.sonarqube/out/ProjectInfo.log
Product projects
---------------------------------------


Test projects
---------------------------------------


Invalid projects
---------------------------------------
{none}


Skipped projects
---------------------------------------
{none}


Excluded projects
---------------------------------------
{none}


ERROR: Job failed: exit code 1

Hi @Momo. Welcome to the community.

FYI I moved your question to a new topic. It’s generally better to start a new topic for a new problem rather than adding to an old topic - shorter, dedicated topics are easier to manage, and problems that superficially look the same can turn out to have different root causes.

There’s nothing obviously wrong in the begin and end logs. The versions of the scanner and MSBuild both look to be new enough. However, it looks like the Sonar targets that were installed in the begin step are not being imported during the MSBuild phase.

Could you post the logs from MSBuild please? If the Sonar targets are being there should be build log output starting with "Sonar: ".

Thanks for your answer.
Sorry I created a new topic, because I Can’t reply here: Problem analysing with Scanner for MSBuild

So to answer to @duncanp :

That’s why I asked help, because all root causes listed in the terminal seems to be OK for me, so I think that the path of building project in the begin step is not the same in the next steps…

Where can I found the log of MSBuild that you ask?

PS:I can’t Reply on this topic, why?

@duncanp That’s my log with normal verbose:

$ dotnet build dot-hello.sln -v n
Microsoft (R) Build Engine version 16.3.2+e481bbf88 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 11/21/2019 5:11:51 PM.
     1>Project "/builds/toto/obs-ci-dotnet/dot-hello.sln" on node 1 (Restore target(s)).
     1>ValidateSolutionConfiguration:
         Building solution configuration "Debug|Any CPU".
       Restore:
         Restoring packages for /builds/toto/obs-ci-dotnet/myWebApp/myWebApp.csproj...
         Committing restore...
         Generating MSBuild file /builds/toto/obs-ci-dotnet/myWebApp/obj/myWebApp.csproj.nuget.g.props.
         Writing assets file to disk. Path: /builds/toto/obs-ci-dotnet/myWebApp/obj/project.assets.json
         Restore completed in 77.48 ms for /builds/toto/obs-ci-dotnet/myWebApp/myWebApp.csproj.
         
         NuGet Config files used:
             /root/.nuget/NuGet/NuGet.Config
         
         Feeds used:
             https://api.nuget.org/v3/index.json
     1>Done Building Project "/builds/toto/obs-ci-dotnet/dot-hello.sln" (Restore target(s)).
   1:2>Project "/builds/toto/obs-ci-dotnet/dot-hello.sln" on node 1 (default targets).
     1>ValidateSolutionConfiguration:
         Building solution configuration "Debug|Any CPU".
   1:2>Project "/builds/toto/obs-ci-dotnet/dot-hello.sln" (1:2) is building "/builds/toto/obs-ci-dotnet/myWebApp/myWebApp.csproj" (2:6) on node 1 (default targets).
     2>BuildTarget:
         Build selected
     2>Done Building Project "/builds/toto/obs-ci-dotnet/myWebApp/myWebApp.csproj" (default targets).
     1>Done Building Project "/builds/toto/obs-ci-dotnet/dot-hello.sln" (default targets).

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:02.00

@mickaelcaro Please allow me to Reply in this Topic, because I can’t!! I don’t have the button “Reply”.

Hi @Momo, please answer directly here now. Thanks !

2 Likes

@Momo dotnet build calls MSBuild under the covers so you can pass any command line arguments that are understood by MSBuild. Specify normal level console logging using -v:normal should be enough to start with e.g. dotnet build dot-hello.sln -v:normal

1 Like