Getting Scan to work with .NET Scanner

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
  • SonarQube 9.1.0.4772
  • Scanner 4.4.0.2
  • what are you trying to achieve

Trying to compare the results of community vs. developer with a test repo. I would like to get one of the sample repos working first provided by SQ. I am using the sonarqube-scanner-msbuild.

  • what have you tried so far to achieve this

Following the general setup instructions for a local instance I am running this in a VM

https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-msbuild/

Here is the output when I try:

dotnet sonarscanner begin /k:"sonarqube-scanner-msbuild2" /d:sonar.host.url="http://localhost:9000" /d:sonar.login="e7ef684742a120d9ed4a68ddad649847ad9324f8"



C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplication\Program.cs(4,18): warning S1118: Add a 'protected' constructor or the 'static' keyword to the class declaration. [C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplication\SomeConsoleApplication.csproj]
C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplication\Program.cs(9,17): warning S2583: Change this condition so that it does not always evaluate to 'true'; some subsequent code is never executed. [C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplication\SomeConsoleApplication.csproj]
C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplication\Program.cs(21,28): warning S3400: Remove this method and declare a constant for this value. [C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplication\SomeConsoleApplication.csproj]
  SomeConsoleApplication -> C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplication\bin\Debug\SomeConsoleApplication.exe
  Sonar: (SomeConsoleApplication.csproj) Project processed successfully
C:\Program Files\dotnet\sdk\5.0.400\Microsoft.Common.CurrentVersion.targets(2203,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Microsoft.VisualStudio.QualityTools.UnitTestFramework". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplicationTest\SomeConsoleApplicationTest.csproj]
C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplicationTest\ProgramTests.cs(2,17): error CS0234: The type or namespace name 'VisualStudio' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) [C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplicationTest\SomeConsoleApplicationTest.csproj]
C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplicationTest\ProgramTests.cs(7,6): error CS0246: The type or namespace name 'TestClassAttribute' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplicationTest\SomeConsoleApplicationTest.csproj]
C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplicationTest\ProgramTests.cs(7,6): error CS0246: The type or namespace name 'TestClass' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplicationTest\SomeConsoleApplicationTest.csproj]
C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplicationTest\ProgramTests.cs(10,10): error CS0246: The type or namespace name 'TestMethodAttribute' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplicationTest\SomeConsoleApplicationTest.csproj]
C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplicationTest\ProgramTests.cs(10,10): error CS0246: The type or namespace name 'TestMethod' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplicationTest\SomeConsoleApplicationTest.csproj]
C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplicationTest\ProgramTests.cs(20,10): error CS0246: The type or namespace name 'TestMethodAttribute' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplicationTest\SomeConsoleApplicationTest.csproj]
C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplicationTest\ProgramTests.cs(20,10): error CS0246: The type or namespace name 'TestMethod' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplicationTest\SomeConsoleApplicationTest.csproj]

Build FAILED.

C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplication\Program.cs(4,18): warning S1118: Add a 'protected' constructor or the 'static' keyword to the class declaration. [C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplication\SomeConsoleApplication.csproj]
C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplication\Program.cs(9,17): warning S2583: Change this condition so that it does not always evaluate to 'true'; some subsequent code is never executed. [C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplication\SomeConsoleApplication.csproj]
C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplication\Program.cs(21,28): warning S3400: Remove this method and declare a constant for this value. [C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplication\SomeConsoleApplication.csproj]
C:\Program Files\dotnet\sdk\5.0.400\Microsoft.Common.CurrentVersion.targets(2203,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Microsoft.VisualStudio.QualityTools.UnitTestFramework". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplicationTest\SomeConsoleApplicationTest.csproj]
C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplicationTest\ProgramTests.cs(2,17): error CS0234: The type or namespace name 'VisualStudio' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) [C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplicationTest\SomeConsoleApplicationTest.csproj]
C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplicationTest\ProgramTests.cs(7,6): error CS0246: The type or namespace name 'TestClassAttribute' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplicationTest\SomeConsoleApplicationTest.csproj]
C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplicationTest\ProgramTests.cs(7,6): error CS0246: The type or namespace name 'TestClass' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplicationTest\SomeConsoleApplicationTest.csproj]
C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplicationTest\ProgramTests.cs(10,10): error CS0246: The type or namespace name 'TestMethodAttribute' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplicationTest\SomeConsoleApplicationTest.csproj]
C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplicationTest\ProgramTests.cs(10,10): error CS0246: The type or namespace name 'TestMethod' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplicationTest\SomeConsoleApplicationTest.csproj]
C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplicationTest\ProgramTests.cs(20,10): error CS0246: The type or namespace name 'TestMethodAttribute' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplicationTest\SomeConsoleApplicationTest.csproj]
C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplicationTest\ProgramTests.cs(20,10): error CS0246: The type or namespace name 'TestMethod' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\User\Desktop\sonarqube-scanner-msbuild\CSharpProject\SomeConsoleApplicationTest\SomeConsoleApplicationTest.csproj]
    4 Warning(s)
    7 Error(s)

I apologize if this a dumb mistake. I am new to SonarQube.

Thanks!
Drew

Hi @kevandersen !

Welcome to SonarSource Community! :sonarsource:

The error is in the log you just posted:

C:\Program Files\dotnet\sdk\5.0.400\Microsoft.Common.CurrentVersion.targets(2203,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Microsoft.VisualStudio.QualityTools.UnitTestFramework". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. 

You may need to follow one of these solutions:

Hey Joe,

Appreciate the quick response. I am not a developer so maybe adding this .dll is trival for most. I am running Visual Studio 2019, and when trying to add the reference from these direction it looks like the menu has changed.

I get to 6 and there is not a box for “Web performance and load testing tools” under “Debugging and testing”

"To resolve this issue, I had to do the following:

  1. Launch the Visual Studio Installer with administrative privileges
  2. If it prompts you to install updates to Visual Studio, do so before continuing
  3. When prompted, click the button to Modify the existing installation
  4. Click on the “Individual components” tab / header along the top
  5. Scroll down to the “Debugging and testing” section
  6. Check the box next to “Web performance and load testing tools”
  7. Click the Modify button on the bottom right corner of the dialog to install the missing DLLs

Once the DLLs are installed, you can add references to them using the method that Agent007 indicated in his answer."

The C# scanner is what we are most interested for a potential developer license purchase if I can get this to run locally.

Loading Visual Studio and manually building the .sln resolved this issue after working with an internal dev more familiar with c#. This ticket can be closed.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.