Visual Studio 2019 PostBuild with dotnet core global tool exits with code 1

We are using SonarQube * Version 8.4.2 (build 36762) installed in a container.
the scanner is installed as a global tool and is version 4.10

I am successful running the scan of my C# solution directly from the command prompt visual studio 2019. i am however, not successful when taking those same commands and placing begin and end into the pre and post-build respectively.

my version of msbuild is 16.4.
I have confirmed the projects have unique GUIDs in the .sln file
I have tried clean build and also re-build. I have checked my BIN folder and there is application output.
the fact that it works from command line but not from within visual studio does suggest user error but alas, it is not obvious to me why it doesn’t work.

Visual Studio is running as administrator

The sonarqube config file is default. I am passing the token and projectID and host URI as command line parameters in the build-events.

The debug output of the end command is the following:

1>12:54:34.085  Pre-processing succeeded.
1>TollBooth -> C:\Users\ejensen\source\repos\TollBooth\TollBooth\bin\Debug\netcoreapp2.1\bin\TollBooth.dll
1>SonarScanner for MSBuild 4.10
1>Using the .NET Core version of the Scanner for MSBuild
1>Post-processing started.
1>12:54:38.518  12:54:38.501  Uninstalling target: C:\Users\ejensen\AppData\Local\Microsoft\MSBuild\4.0\Microsoft.Common.targets\ImportBefore\SonarQube.Integration.ImportBefore.targets
1>12:54:38.518  12:54:38.503  Uninstalling target: C:\Users\ejensen\AppData\Local\Microsoft\MSBuild\10.0\Microsoft.Common.targets\ImportBefore\SonarQube.Integration.ImportBefore.targets
1>12:54:38.518  12:54:38.505  Uninstalling target: C:\Users\ejensen\AppData\Local\Microsoft\MSBuild\11.0\Microsoft.Common.targets\ImportBefore\SonarQube.Integration.ImportBefore.targets
1>12:54:38.518  12:54:38.507  Uninstalling target: C:\Users\ejensen\AppData\Local\Microsoft\MSBuild\12.0\Microsoft.Common.targets\ImportBefore\SonarQube.Integration.ImportBefore.targets
1>12:54:38.518  12:54:38.508  Uninstalling target: C:\Users\ejensen\AppData\Local\Microsoft\MSBuild\14.0\Microsoft.Common.targets\ImportBefore\SonarQube.Integration.ImportBefore.targets
1>12:54:38.518  12:54:38.51  Uninstalling target: C:\Users\ejensen\AppData\Local\Microsoft\MSBuild\15.0\Microsoft.Common.targets\ImportBefore\SonarQube.Integration.ImportBefore.targets
1>12:54:38.518  12:54:38.511  Uninstalling target: C:\Users\ejensen\AppData\Local\Microsoft\MSBuild\Current\Microsoft.Common.targets\ImportBefore\SonarQube.Integration.ImportBefore.targets
1>12:54:38.518  12:54:38.518  sonar.verbose=true was specified - setting the log verbosity to 'Debug'
1>12:54:38.519  Loading the SonarQube analysis config from C:\Users\ejensen\source\repos\TollBooth\TollBooth\.sonarqube\conf\SonarQubeAnalysisConfig.xml
1>12:54:38.519  Not running under TeamBuild
1>12:54:38.519  Analysis base directory: C:\Users\ejensen\source\repos\TollBooth\TollBooth\.sonarqube
1>Build directory:
1>Bin directory: C:\Users\ejensen\source\repos\TollBooth\TollBooth\.sonarqube\bin
1>Config directory: C:\Users\ejensen\source\repos\TollBooth\TollBooth\.sonarqube\conf
1>Output directory: C:\Users\ejensen\source\repos\TollBooth\TollBooth\.sonarqube\out
1>Config file: C:\Users\ejensen\source\repos\TollBooth\TollBooth\.sonarqube\conf\SonarQubeAnalysisConfig.xml
1>Generating SonarQube project properties file to C:\Users\ejensen\source\repos\TollBooth\TollBooth\.sonarqube\out\
1>The SonarQube MSBuild integration failed: SonarQube was unable to collect the required information about your projects.
1>Possible causes:
1>  1. The project has not been built - the project must be built in between the begin and end steps
1>  2. An unsupported version of MSBuild has been used to build the project. Currently MSBuild 14.0.25420.1 and higher are supported.
1>  3. The begin, build and end steps have not all been launched from the same folder
1>  4. None of the analyzed projects have a valid ProjectGuid and you have not used a solution (.sln)
1>Writing processing summary to C:\Users\ejensen\source\repos\TollBooth\TollBooth\.sonarqube\out\ProjectInfo.log
1>Generation of the sonar-properties file failed. Unable to complete SonarQube analysis.
1>12:54:38.549  Post-processing failed. Exit code: 1

I am wondering if perhaps it’s the 3rd point around folders but I am not sure if I am to correct that in my .csproj or .sln files. I tried cd $(SolutionPath) before the begin and end commands and it did not affect the result.

Hi Folks… I believe this is user-error. I was under the impression that Visual Studio native build uses MSBuild but this article suggests that this is not the case. So I believe that a build must be fashioned in a more controlled manner to properly analyze the code in SonarQube.

Hi @ejensen,

Welcome to the community and thank you for your follow up of your own thread. It might help other users as well.

VS build is indeed not the same as MSBuild of your solution. Adding build events would trigger the analysis in SQ for each of your development build or local test run build. That’s not intended scenario for scanning your projects due to performance penalty.

Unfortunately, we currently don’t have a single-click way in VS to trigger the build and analysis. But you can easily write a short script to do that when really needed. And you can add such script to your External Tools configuration, add it as a menu item/tool bar command/keyboard shortcut.

You can also use SonarLint extension to see the issues directly in VS while you write them.