sonarqube - SonarScanner for MsBuild 可以扫描 TSQL
问题描述
我安装了 SonarQube,我们正在尝试在包含以下代码类型的产品上运行它
- Javascript
- VBScript
- XML
- C#
- VB.net
- T/SQL
现在我们运行它来扫描除 T/SQL 代码之外的所有代码。
此 TSQL 代码与所有其他代码位于同一目录下,但没有特定的 Visual Studio 项目。
我们能够在 SQL 上运行扫描的唯一方法是使用标准运行程序sonarqube
,但这会导致在我们的仪表板上创建一个新产品。
任何想法或建议。
解决方案
目前,如果您希望分析 TSQL 文件并将其显示在与其他代码相同的 SonarQube 项目下,则需要从 MSBuild 项目中引用它。
有几种方法可以做到这一点:
1) 使用如下代码段在现有项目之一中包含 TSQL 文件:
<ItemGroup>
<!-- Include additional files that should be analyzed by the SonarScanner for MSBuild -->
<None Include="*.tsql" >
<!-- Don't show the items in the Solution Explorer -->
<Visible>False</Visible>
</None>
</ItemGroup>
2) 创建一个单独的虚拟 MSBuild 项目,其唯一目的是指定要分析的其他文件。这稍微复杂一些,因为虚拟项目需要一些额外的内容才能使其与 SonarScanner for MSBuild 目标一起使用。以下模板适用于 v4.3 的扫描仪,也应该适用于最近的早期版本。
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- The only purpose of this project is to specify additional files to be analyzed by the SonarScanner for MSBuild -->
<!-- 1. Set a unique GUID id for the project -->
<PropertyGroup>
<ProjectGuid>{EA2BAA27-D799-4FBE-9430-7499ACF3E431}</ProjectGuid>
</PropertyGroup>
<!-- 2. Specify the files to be analysed -->
<ItemGroup>
<SonarQubeAnalysisFiles Include="**\*.js" />
</ItemGroup>
<!-- ******************************************************** -->
<!-- Boilerplate - no need to change anything below this line -->
<!-- ******************************************************** -->
<!-- Import the SQ targets (will only exist if the scanner "begin" step has been executed) -->
<PropertyGroup>
<SQImportBeforeTargets>$(localappdata)\Microsoft\MSBuild\$(MSBuildToolsVersion)\Microsoft.Common.targets\ImportBefore\SonarQube.Integration.ImportBefore.targets</SQImportBeforeTargets>
</PropertyGroup>
<Import Condition="Exists('$(SQImportBeforeTargets)')" Project="$(SQImportBeforeTargets)" />
<!-- Re-define the standard step of targets used in builds -->
<Target Name="Build" />
<Target Name="Clean" />
<Target Name="CoreCompile" />
<Target Name="Rebuild" DependsOnTargets="Clean;Build" />
<!-- Re-define one of the standard SQ targets as we have already set the list of files to analyze above -->
<Target Name="CalculateSonarQubeFilesToAnalyze" >
<PropertyGroup>
<!-- Set a property indicating whether there are any files to analyze -->
<AnalysisFilesExist Condition=" @(SonarQubeAnalysisFiles) != '' ">true</AnalysisFilesExist>
</PropertyGroup>
</Target>
</Project>
推荐阅读
- python - Xarray - 根据空间位置动态选择时间维度
- augmented-reality - Google Pixel 5 对 ARCore 功能的支持程度
- html - 仅当它是唯一具有给定类选择器的元素时才显示元素
- python - 如何返回仅包含小数点后第二位的 python 列表?
- moodle - 在moodle中限制开始一门课程直到另一门课程结束
- javascript - 使用 Javascript 在 JSP 中添加 Bootstrap 微调器
- python - Curl URL 的等效 Python 代码是什么。是否有任何教程显示如何将 curl 转换为 python?
- ios - 在 swiftui 中是否有一种简单的方法来创建像 Mail 这样的 3 层 master-context-detail 应用程序?
- list - DART/FLUTTER - 清空列表:myList.clear() 和 myList=[] 之间的真正区别是什么?
- python - ValueError:时间数据 '2021-07-28 10:27:51,834' 与格式 '&Y-%m-%d %H:%M:%S,%f' 不匹配