Build Failed on SonarQube for VB.NET App

Good Day SonarFolks :upside_down_face:,

I am having issues scanning VB.NET source code.

I basically followed the tutorial on the link SonarQube Tutorial for C#, VB.NET, ASP.NET, ASP.NET MVC, ASP.NET Core however in my case when I have to build the application e.g. running the following command “MsBuild.exe /t:Rebuild” I get the error below. I have tried to specify the location of MSBuild but I still get the same error.

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)

-SonarQube - sonarqube9.5.0.56709
-Sonar Scanner - sonar-scanner-msbuild-5.5.3.43281-net46
-Windows 10 - OS Version: 10.0.19042 - RID: win10-x64
-Visual Studio 2022 Community Edition
-java 11.0.11 2021-04-20 LTS
-.NET SDK (reflecting any global.json): Version: 6.0.203 - Commit: a20feadf6d

  • what are you trying to achieve

I am trying to scan a vb.net project using sonar-scanner on sonarqube

  • what have you tried so far to achieve this
    I have tried to copy the ItraceApplication.csproj file on the project root folder.
    I have tried running the command using the Visual Studio Powershell & CMD.
    I have tried specifying the location of MSBuild for both the C:\Program Files (x86)\MSBuild\14.0\Bin & C:\Program Files\Microsoft VisualStudio\2022\Community\MSBuild\Current\Bin locations.
    I have tried looking for articles online that speak to this issue but I am not finding anything that speaks to this.

Response Error Below when I run: either "C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin"MsBuild.exe /t:Rebuild or "C:\Program Files (x86)\MSBuild\14.0\Bin"MsBuild.exe /t:Rebuild command

C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\Microsoft.CSharp.CurrentVersion.targets(318,5): error MSB4019: The imported project "C:\Program
 Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets" was not found. Confirm that the expression in the Import declaratio
n "C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets" is correct, and that the file exists on disk. [C:\User
s\<>\Downloads\SonarQube\<>\<>\<>\<>.csproj]
Done Building Project "C:\Users\<>\Downloads\SonarQube\<>\<>\<>\<>.csproj" (default targets) -- FAILED.

Done Building Project "C:\Users\<>\Downloads\SonarQube\<>\<>\<>.sln" (default targets) -- FAILED.


Build FAILED.

"C:\Users\<>\Downloads\SonarQube\<>\<>\<>.sln" (default target) (1) ->
"C:\Users\<>\Downloads\SonarQube\<>\<>\<>\<>.csproj" (default target) (2) ->
  C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\Microsoft.CSharp.CurrentVersion.targets(318,5): error MSB4019: The imported project "C:\Progr
am Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets" was not found. Confirm that the expression in the Import declarat
ion "C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets" is correct, and that the file exists on disk. [C:\Us
ers\<>\Downloads\SonarQube\<>\<>\<>\<>.csproj]

    0 Warning(s)
    1 Error(s)

Kind Regards,

Hi @sanele,

A few questions:

  • are you running the analysis on your local machine, or on a CI machine? If CI, which CI system are you using? (Azure DevOps, GitHub Actions, Jenkins etc)
  • does the project build step work correctly if you skip the scanner begin step?

The error being reported by MSBuild isn’t related to the SonarQube integration; it’s a more general error related to the standard MSBuild targets.

Also, if you are building on your local machine, make sure you are running from a VS developer command prompt. Then you wouldn’t need to fully-qualify the path to MSBuild.

Hi,

Thanks for the feedback, to answer your questions:

  • are you running the analysis on your local machine, or on a CI machine? If CI, which CI system are you using? (Azure DevOps, GitHub Actions, Jenkins etc.) * am running it locally from my workstation.
    does the project build step work correctly if you skip the scanner begin step?. I will try this and revert back with findings

The error being reported by MSBuild isn’t related to the SonarQube integration; it’s a more general error related to the standard MSBuild targets. Do you have any articles that speak on resolving this issue ?

Also, if you are building on your local machine, make sure you are running from a VS developer command prompt. Then you wouldn’t need to fully-qualify the path to MSBuild. Noted