SonarAnalyzer failed on Windows with CS0006

Yes, you are right. I have to think about we can solve that.

The NUKE code (defines the build) is C# code, this should be clean code, checked by SQ etc.

Here is some additional information. I hope it helps:

c:\Users\s_TFSBuilder\.sonar\ is %userprofile%\.sonar (with s_TFSBuilder being the user account used on the agent).
It stores data that might be needed by multiple analyses and multiple scanners (even non-.NET scanners). For example, it caches analyzers and other artifacts downloaded by the scanner.

C:\Users\***\AppData\Local\Temp\.sonarqube or %temp%\.sonarqube is used by the Scanner for .NET (any flavor, .NET and .NET Framework) to prepare an analysis. The BEGIN step will copy the relevant files (most notably the analyzer DLLs) to this folder. It also acts as a cache because the BEGIN step will attempt to reuse files from this folder. However, the primary use is to store files used for analysis during the build.

c:\build\_work\979 is most likely the project’s build directory (compare Predefined variables - Azure Pipelines | Microsoft Learn).
The .sonarqube folder in the build directory contains the additional targets for the build and the configuration for the analysis.

The general process is as follows:

BEGIN:

  1. Download the needed analyzers and to %temp%\.sonarqube.
  2. If a project\.sonarqube folder exists (from a previous run), clean it.
  3. Prepare the project\.sonarqube folder. Link the analyzer files in project\.sonarqube\conf\SonarQubeAnalysisConfig.xml.

Build:

  1. Pickup additional targets from project\.sonarqube\bin\targets.
  2. Follow the links in project\.sonarqube\conf\SonarQubeAnalysisConfig.xml to include the analyzer files from %temp%\.sonarqube.
  3. Write the analysis results to project\.sonarqube\out.

END:

  1. Get the analysis results from project\.sonarqube\out.
  2. Upload them to the SonarQube server.
  3. Remove the targets from project\.sonarqube\bin\targets (but leave the rest of the folder untouched).

Good luck!

Ok, this helps some steps. So, it is clear, when %temp%\.sonarqube is removed (because we weekly cleanup %temp%, the build can fail because project\.sonarqube\bin\targets refers to %temp%\.sonarqube which is invalid now.
Intentionally the BEGIN step is performed later. First the NUKE project is build, then started which makes BEGIN, COMPILE (the real target), END.

Now I’m wondering how a build within c:\build\_work\979\s can be influenced by the targets in c:\build\_work\979\.sonarqube.
Can you help me to understand this?

Would it be possible to adopt the targets file to ignore analysis if %temp%\.sonarqube is not available?

There is an extra target file placed in the ImportBefore directory. Check my earlier post for more details.

You can simply remove all files from project\.sonarqube\bin\targets. In fact, the End step should remove the targets file from there already. If it’s still there, it means your End step did not run for this project.