# How to inject sonar-project.properties into msbuild in sonarqube

**URL:** <https://community.sonarsource.com/t/how-to-inject-sonar-project-properties-into-msbuild-in-sonarqube/7172>\
**Category:** SonarQube Server / Community Build\
**Tags:** msbuild, sonarqube, scanner\
**Created:** [February 22, 2019, 3:14pm UTC](https://community.sonarsource.com/t/how-to-inject-sonar-project-properties-into-msbuild-in-sonarqube/7172 "2019-02-22T15:14:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![r.kumar](https://avatars.discourse-cdn.com/v4/letter/r/858c86/32.png) [@r.kumar](https://community.sonarsource.com/u/r.kumar)\
**Post date:** [February 22, 2019, 3:14pm UTC](https://community.sonarsource.com/t/how-to-inject-sonar-project-properties-into-msbuild-in-sonarqube/7172/1 "2019-02-22T15:14:35Z")

</div>

I have a c-sharp solution (say sample.sln), but to run sonarqube analysis, as per the docs, i have run the following command:

```
 ".\3rdparty\sonarqube\msbuild\SonarScanner.MSBuild.exe" begin /k:"comm" 
  /n:"comm" /v:"2.0" 
  /d:sonar.cs.dotcover.reportsPaths= 
  "D:\Jenkins\workspace\comm\TEST\CoverageReport.html" 
  /d:sonar.host.url="http://101.149.24.128"
  /d:sonar.sources="D:\Jenkins\workspace\comm\source\*.cs"

  msbuild comm.sln /t:Rebuild

  ".\3rdparty\sonarqube\msbuild\SonarScanner.MSBuild.exe" end

```

but getting this error :

```
  SONAR_SCANNER_OPTS is not configured. Setting it to the default value of -Xmx1024m
Calling the SonarQube Scanner...
INFO: Scanner configuration file: D:\Jenkins\workspace\comm\3rdparty\sonarqube\msbuild\sonar-scanner-3.2.0.1227\bin\..\conf\sonar-scanner.properties
INFO: Project root configuration file: D:\Jenkins\workspace\comm\.sonarqube\out\sonar-project.properties
INFO: SonarQube Scanner 3.2.0.1227
INFO: Java 1.8.0_151 Oracle Corporation (64-bit)
INFO: Windows Server 2016 10.0 amd64
INFO: SONAR_SCANNER_OPTS=-Xmx1024m
INFO: User cache: C:\Users\jenkins\.sonar\cache
INFO: SonarQube server 6.7.5
INFO: Default locale: "en_US", source code encoding: "windows-1252" (analysis is platform dependent)
INFO: Publish mode
INFO: Load global settings
INFO: Load global settings (done) | time=278ms
INFO: Server id: 7950B4AD-AWYRoMpRpurWib7aM-qP
INFO: User cache: C:\Users\jenkins\.sonar\cache
INFO: Load plugins index
INFO: Load plugins index (done) | time=84ms
INFO: Process project properties
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 13.565s
INFO: Final Memory: 6M/84M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarQube Scanner execution
ERROR: Unable to load component class org.sonar.scanner.scan.ProjectLock
ERROR: Caused by: Unable to load component class org.sonar.scanner.scan.DefaultInputModuleHierarchy
ERROR: Caused by: Unable to load component class org.sonar.scanner.scan.ProjectBuildersExecutor
ERROR: Caused by: Unable to load component class com.talanlabs.sonar.plugins.gitlab.CommitProjectBuilder
ERROR: Caused by: Unable to load component class com.talanlabs.sonar.plugins.gitlab.GitLabPluginConfiguration
ERROR: Caused by: Unable to load component class org.sonar.scanner.scan.MutableProjectSettings
ERROR: Caused by: Unable to load component class org.sonar.api.batch.bootstrap.ProjectReactor
**ERROR: Caused by: Illegal char <*> at index 43: D:\Jenkins\workspace\comm\source\*.cs**
ERROR: 
The SonarQube Scanner did not complete successfully

```

so i thought of adding, all the sonar related properties into sonar-project.properties, and kept inside the project root folder, and ran the analysis. but got an error below.

```
  sonar-project.properties files are not understood by the SonarScanner for MSBuild. Remove those files from the following folders: D:\Jenkins\workspace\comm.

```

what i could infer is, we cannot set sonar-project.properties for msbuild ? is it ?

**So then how to do include/exclude files/folders from code coverage in sonar analysis ? I don’t have admin access, to set administrative global exclusions**

Any help ?

P.S using sonarqube LTS 6.7.6

---

<div class="post-metadata">

**Author:** ![Joe](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/joe/32/14820_2.png) [@Joe](https://community.sonarsource.com/u/Joe)\
**Post date:** [July 1, 2021, 1:53am UTC](https://community.sonarsource.com/t/how-to-inject-sonar-project-properties-into-msbuild-in-sonarqube/7172/2 "2021-07-01T01:53:57Z")

</div>

Hi @r.kumar ,

Sorry for a late reply. This is for the posterity of any future Community members.

> [@r.kumar](#):
>
> what i could infer is, we cannot set sonar-project.properties for msbuild ? is it ?

`sonar-project.properties` file does not work with projects scanned with Sonar Scanner for MSBuild. If you want to set those parameters, then either do it within the Azure DevOps pipeline.yaml or within your .csproj file, both of which can be version controlled. Here’s an example with adding those sonar analysis parameters to a .csproj file:

> [@Scan repository containing .netcore & swift projects](https://community.sonarsource.com/t/scan-repository-containing-netcore-swift-projects/36040/2):
>
> For customizing your C# project with sonar-project analysis properties, you can add **SonarQubeSetting** nodes for each analysis property in the \*.csproj file for your C# module:
> 
> ```auto
> <ItemGroup>
> <SonarQubeSetting Include="sonar.exclusions">
> <Value>NotAnalyzedFile.cs,Libraries/**/*.*</Value>
> </SonarQubeSetting>
> </ItemGroup>
> 
> ```

However, most users with Azure DevOps pipelines version control these Sonar analysis parameters within their pipeline yaml in the PrepareSonarAnalysis task.

Joe

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/system/32/31083_2.png) [@system](https://community.sonarsource.com/u/system)\
**Post date:** [July 8, 2021, 1:54am UTC](https://community.sonarsource.com/t/how-to-inject-sonar-project-properties-into-msbuild-in-sonarqube/7172/3 "2021-07-08T01:54:56Z")

</div>

Closed on July 8, 2021, 1:54am UTC

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