SonarQube MSBuild无法排除文件

我正在使用msian在debian上运行分析,使用以下命令:

mono /msbuild/SonarQube.Scanner.MSBuild.exe begin /d:sonar.login= /d:sonar.host.url=https:// /d:sonar.exclusions=test/**/* /k: 

但是end命令中:

 INFO: Index files INFO: Excluded sources: INFO: test/**/* INFO: 17 files indexed INFO: 0 files ignored because of inclusion/exclusion patterns INFO: Quality profile for cs: Sonar way INFO: Excluded sources for coverage: INFO: test/** 

并且我的服务器的UI分析包括来自test/文件夹的文件。

为什么它无法忽略特定文件?

使用SonarQube 6.7sonar-scanner:3.3

正如您的尝试所certificate的那样,排除很难从分析方面正确设置。 您最好的选择是从UI设置这些。

我设法解决这种情况的唯一方法是.csproj下行添加到我想要排除的项目的.csproj文件中

  true 

我升级到SonarQube Scanner for MSBuild 4.0.2之后遇到了同样的问题

正如pkaramol所说,并且通过查看文档[ 1,2 ],这似乎是唯一的解决方案,因为sonar.exclusions仅匹配每个项目文件夹中的文件而不匹配解决方案文件夹。 我为我的CI编写了一个python(> = 3.5)脚本,它将这些行添加到我想要排除的项目中。

 import os import glob import shutil SOURCEDIR_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) SQ_EXCLUDE_TAG = """   true  """ 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')