I am running an analysis using msbuild on debian, using the following command:
mono /msbuild/SonarQube.Scanner.MSBuild.exe begin /d:sonar.login=
The only way I have managed to get around this situation is by adding the following line to the .csproj
file of the projects I want excluded
<!-- Exclude the project from SonarQube analysis -->
<SonarQubeExclude>true</SonarQubeExclude>
Exclusions are difficult to set correctly from the analysis side, as demonstrated by your attempt. Your best bet is to set these from the UI.
I had the same problem with after I upgraded to SonarQube Scanner for MSBuild 4.0.2
As pkaramol stated and by looking at the docs [1,2] this seems to be the only solution because sonar.exclusions matches only files in each project folder and not the solution folder. I wrote a python (>= 3.5) script for my CI which adds those lines to projects I want to be excluded.
import os
import glob
import shutil
SOURCEDIR_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
SQ_EXCLUDE_TAG = """
<PropertyGroup>
<!-- Exclude the project from analysis -->
<SonarQubeExclude>true</SonarQubeExclude>
</PropertyGroup>
"""
def add_sq_exclude_tag(project_name):
search_path = os.path.join(SOURCEDIR_PATH, '**', '{}.csproj'.format(project_name))
for file_path in glob.iglob(search_path, recursive=True):
with open(file_path, 'r', encoding='utf8') as outfile:
lines = outfile.readlines()
project_end_tag = lines[-1]
lines[-1] = SQ_EXCLUDE_TAG
lines.append(project_end_tag)
with open(file_path, 'w', encoding='utf8') as outfile:
outfile.writelines(lines)
print('Added sonarqube exclude tag to {}'.format(file_path))
if __name__ == '__main__':
add_sq_exclude_tag('*csprojFileConatainsThisString*')
add_sq_exclude_tag('exactCsprojFileNameWithoutFileEnding')