# C# Dotnet can't analyze - azure devops!

**URL:** <https://community.sonarsource.com/t/c-dotnet-cant-analyze-azure-devops/132435>\
**Category:** SonarQube Server / Community Build\
**Tags:** azuredevops-services, dotnet\
**Created:** [December 19, 2024, 8:38am UTC](https://community.sonarsource.com/t/c-dotnet-cant-analyze-azure-devops/132435 "2024-12-19T08:38:31Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![sonarhelp](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@sonarhelp](https://community.sonarsource.com/u/sonarhelp)\
**Post date:** [December 19, 2024, 8:38am UTC](https://community.sonarsource.com/t/c-dotnet-cant-analyze-azure-devops/132435/1 "2024-12-19T08:38:31Z")

</div>

SonarQube Community - latest  
Using Azure Devops extension  
Able to analyze js.typescript c ode, but C# code says 0 lines of code on sonarqube

I’m running on a self hosted build agent  
.NET 8.0  
Installed dotnet-sdk-8.0 o  
installed dotnet tool install --global dotnet-sonarscanner

My yaml

```
- task: SonarQubePrepare@7
    inputs:
      SonarQube: 'SonarQube Service Connection'
      scannerMode: 'dotnet'
      projectKey: ''

```

I then run dotnet build

Then  
- task: SonarQubeAnalyze@7

My logs say this in the beginning

```auto
SonarScanner for MSBuild 9.0.2
Using the .NET Core version of the Scanner for MSBuild
Post-processing started.
Calling the SonarScanner CLI...
.
.
.
INFO: SonarScanner 5.0.1.3006

**It gives me this warning**

WARN: Your project contains C# files which cannot be analyzed with the scanner you are using. To analyze C# or VB.NET, you must use the SonarScanner for .NET 5.x or higher,

```

I;ve already read the ADO integration docs and  
[.NET environments | SonarQube Community Build Documentation](https://docs.sonarsource.com/sonarqube-community-build/analyzing-source-code/dotnet-environments/getting-started-with-net/#net)  
and that’s why installed `dotnet tool install --global dotnet-sonarscanner` on my build agent.

I know the azure sonarqube server extension has the SonarScanner for dotnet built in, so I didn’t even need to install it on the agent.  
So it should work…

Should I revert and use the depreciated version of the Azure Devops Sonarqube task  
for example ,

SonarQubePrepare@5 instead of SonarQubePrepare@7

cause in version seven, you declare scannerMode: dotnet  
in version five, you declare scannerMode: MSBuild

someone was able to fix this issue with version 5, [Sensor C# Not Picking Up Some .cs Files - SonarQube Server / Community Build - Sonar Community](https://community.sonarsource.com/t/sensor-c-not-picking-up-some-cs-files/73947/4)

So… is this a bug with azure sonarqube devops extension?

Please help asap

---

<div class="post-metadata">

**Author:** ![Colin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/colin/32/55255_2.png) [@Colin](https://community.sonarsource.com/u/Colin)\
**Post date:** [December 19, 2024, 9:13am UTC](https://community.sonarsource.com/t/c-dotnet-cant-analyze-azure-devops/132435/2 "2024-12-19T09:13:30Z")

</div>

Hey there.

Can you please share your full Azure DevOps Pipeline YML?

It would also help to see the entire logs from the pipeline.

---

<div class="post-metadata">

**Author:** ![sonarhelp](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@sonarhelp](https://community.sonarsource.com/u/sonarhelp)\
**Post date:** [December 19, 2024, 9:28am UTC](https://community.sonarsource.com/t/c-dotnet-cant-analyze-azure-devops/132435/3 "2024-12-19T09:28:45Z")

</div>

@Colin

//  
- task: SonarQubePrepare@7  
inputs:  
SonarQube: ‘SonarQube Service Connection’  
scannerMode: ‘dotnet’  
projectKey: ‘…’

```
  - task: DotNetCoreCLI@2
    inputs:
      command: 'build'
      projects: "$(Build.SourcesDirectory)/...../*.csproj"

  - task: SonarQubeAnalyze@7

```

//  
logs  
for  
SonarQube analyze @7 task

(blurred out for security purposes):  
INFO: Indexing files…  
INFO: Indexing files of module ‘’  
INFO: Base dir: /…/\_work/1/s/…/FOLDER  
INFO: Source paths: xxx.cs, xxx/yy…

…

INFO: X files indexed  
…  
INFO: ------------- Run sensors on module X  
INFO: Load metrics repository  
INFO: Load metrics repository (done) | time=72ms  
INFO: Sensor C# Project Type Information [csharp]  
INFO: Sensor C# Project Type Information [csharp] (done) | time=1ms  
INFO: Sensor C# Analysis Log [csharp]  
INFO: Sensor C# Analysis Log [csharp] (done) | time=26ms  
INFO: Sensor C# Telemetry [csharp]  
INFO: Sensor C# Telemetry [csharp] (done) | time=4ms  
INFO: Sensor C# Properties [csharp]  
INFO: Sensor C# Properties [csharp] (done) | time=0ms  
INFO: Sensor HTML [web]  
INFO: Sensor HTML [web] (done) | time=3ms  
INFO: Sensor JaCoCo XML Report Importer [jacoco]  
INFO: ‘sonar.coverage.jacoco.xmlReportPaths’ is not defined. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml  
INFO: No report imported, no coverage information will be imported by JaCoCo XML Report Importer  
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=2ms  
INFO: Sensor Java Config Sensor [iac]  
.  
.  
.  
.  
Logs then show it is able to analyze typescript etc code…

then

INFO: ------------- Run sensors on project X  
INFO: Sensor C# Telemetry processor [csharp]  
INFO: Sensor C# Telemetry processor [csharp] (done) | time=3ms  
INFO: Sensor C# [csharp]  
WARN: Your project contains C# files which cannot be analyzed with the scanner you are using. To analyze C# or [VB.NET](http://VB.NET), you must use the SonarScanner for .NET 5.x or higher, see [https://redirect.sonarsource.com/doc/install-configure-scanner-msbuild.html](https://redirect.sonarsource.com/doc/install-configure-scanner-msbuild.html)  
INFO: Sensor C# [csharp] (done) | time=2ms  
INFO: Sensor Analysis Warnings import [csharp]  
INFO: Sensor Analysis Warnings import [csharp] (done) | time=13ms  
INFO: Sensor C# File Caching Sensor [csharp]  
INFO: Sensor C# File Caching Sensor [csharp] (done) | time=17ms  
INFO: Sensor Zero Coverage Sensor  
INFO: Sensor Zero Coverage Sensor (done) | time=37ms

---

<div class="post-metadata">

**Author:** ![Colin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/colin/32/55255_2.png) [@Colin](https://community.sonarsource.com/u/Colin)\
**Post date:** [December 19, 2024, 9:33am UTC](https://community.sonarsource.com/t/c-dotnet-cant-analyze-azure-devops/132435/4 "2024-12-19T09:33:41Z")

</div>

This is neither your full pipeline, or the complete logs from your build. I’m sorry, there’s not enough information in what you’ve shared to be helpful.

---

<div class="post-metadata">

**Author:** ![sonarhelp](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@sonarhelp](https://community.sonarsource.com/u/sonarhelp)\
**Post date:** [December 19, 2024, 9:37am UTC](https://community.sonarsource.com/t/c-dotnet-cant-analyze-azure-devops/132435/5 "2024-12-19T09:37:04Z")

</div>

@Colin  
There’s nothing else related to this in my pipeline. This is the step where the .NET code is being built in the pipeline.

The logs I shared show what happens during the task that analyzes after the dotnet build  
It successfully performs analysis on TypeScript and JavaScript code.

I cant share the whole logs for security purposes  
@Colin

---

<div class="post-metadata">

**Author:** ![sonarhelp](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@sonarhelp](https://community.sonarsource.com/u/sonarhelp)\
**Post date:** [December 20, 2024, 8:30am UTC](https://community.sonarsource.com/t/c-dotnet-cant-analyze-azure-devops/132435/6 "2024-12-20T08:30:58Z")

</div>

@Colin  
Seems like my sonar scanner is version SonarScanner 5.0.1.3006 even though I’m using the latest Azure DevOps SonarQube version, so there’s a bug for SonarQube extension as you agreed to @Colin

So I specified the latest version in my prepare

```
  - task: SonarQubePrepare@7
    inputs:
      SonarQube: 'SonarQube Connection'
      scannerMode: 'dotnet'
      projectKey: ''
      projectName: ''
      msBuildVersion: '9.0.2.104486'

```

In the SonarQubeprepare logs it says

```auto
**Found tool in cache: SonarScanner .NET 9.0.2 x64**

/usr/bin/dotnet /azp/_work/_tool/SonarScanner .NET/9.0.2/x64/SonarScanner.MSBuild.dll begin /k:al;smdl;asdm

SonarScanner for MSBuild 9.0.2

Using the .NET Core version of the Scanner for MSBuild

```

However in SOnarQubeAnalys log it still says the version is this:

```auto
SonarScanner for MSBuild 9.0.2

Using the .NET Core version of the Scanner for MSBuild

Post-processing started.

Calling the SonarScanner CLI...

INFO: Scanner configuration file: /azp/_work/_tool/SonarScanner .NET/9.0.2/x64/sonar-scanner-5.0.1.3006/conf/sonar-scanner.properties

INFO: Project root configuration file: /azp/_work/1/.sonarqube/out/sonar-project.properties

**INFO: SonarScanner 5.0.1.3006**

INFO: Java 17.0.11 Eclipse Adoptium (64-bit)

INFO: Linux 5.15.164.1-1.cm2 amd64

INFO: User cache: /home/agent/.sonar/

```

---

<div class="post-metadata">

**Author:** ![sonarhelp](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@sonarhelp](https://community.sonarsource.com/u/sonarhelp)\
**Post date:** [December 20, 2024, 9:25am UTC](https://community.sonarsource.com/t/c-dotnet-cant-analyze-azure-devops/132435/7 "2024-12-20T09:25:48Z")

</div>

From

> [@How do you specify the sonarscanner version that is being used with SonarQubeAnalyze task?](https://community.sonarsource.com/t/how-do-you-specify-the-sonarscanner-version-that-is-being-used-with-sonarqubeanalyze-task/76028/7):
>
> Without really knowing anything about .Net on linux, the .Net section at [https://docs.sonarqube.org/latest/analysis/azuredevops-integration/](https://docs.sonarqube.org/latest/analysis/azuredevops-integration/) has this .yml example trigger: - master # or the name of your main branch - feature/\* steps: # Prepare Analysis Configuration task - task: SonarQubePrepare@5 inputs: SonarQube: 'YourSonarqubeServerEndpoint' scannerMode: 'MSBuild' projectKey: 'YourProjectKey' # Run Code Analysis task - task: SonarQubeAnalyze@5 # Publish Quality Gate Resul…

Sonar employee says you cant specify the scanner version in the prepare task…  
But documentation says you can via msBuildVersion paramtee

I’ve tried SonarQubexxx@7 and SonarQubexxx@5 and both don’t get the most up to date sonarscanner version

---

<div class="post-metadata">

**Author:** ![denis.troller](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/denis.troller/32/49117_2.png) [@denis.troller](https://community.sonarsource.com/u/denis.troller)\
**Post date:** [December 20, 2024, 4:13pm UTC](https://community.sonarsource.com/t/c-dotnet-cant-analyze-azure-devops/132435/8 "2024-12-20T16:13:40Z")

</div>

Hi there, @sonarhelp

The first line of your log indicates you are indeed using version 9.0.2 of the SonarScanner for .NET:

> SonarScanner for MSBuild 9.0.2

The line you are referring to is an indication of the version of the embedded Scanner CLI (this is a technical detail of the implementation), which is v5.0 at this time.

As for why your get this error, @Colin is right. Without more details on your pipeline (prepare, build and analyze tasks at least) and your logs (again, prepare, build, and analyze tasks), it will be difficult to help more. You can send the logs (please generate them by setting sonar.verbose to true in your Prepare task’s extraProperties input) by direct message to us if you do not want to post them publicly (which is understandable).

Denis

---

<div class="post-metadata">

**Author:** ![sonarhelp](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@sonarhelp](https://community.sonarsource.com/u/sonarhelp)\
**Post date:** [December 20, 2024, 10:48pm UTC](https://community.sonarsource.com/t/c-dotnet-cant-analyze-azure-devops/132435/9 "2024-12-20T22:48:16Z")

</div>

So the sonar scanner version is 5 on purpose even though the latest is 9.x.x??

My logs say the version 5 isnt enough for the c# files

I can send logs privately

---

<div class="post-metadata">

**Author:** ![denis.troller](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/denis.troller/32/49117_2.png) [@denis.troller](https://community.sonarsource.com/u/denis.troller)\
**Post date:** [January 2, 2025, 8:19am UTC](https://community.sonarsource.com/t/c-dotnet-cant-analyze-azure-devops/132435/10 "2025-01-02T08:19:32Z")

</div>

@sonarhelp as I said, this is the version of an internal component, logged for purposes of diagnostics, nothing more. The actual scanner version is printed at the start, and is indeed 9.x.  
Please do send the logs via private message so we can help, as well as your pipeline.

Denis
