【问题标题】:Can SonarScanner for MsBuild scan TSQLSonarScanner for MsBuild 可以扫描 TSQL
【发布时间】:2019-02-19 06:12:26
【问题描述】:

我已安装 SonarQube,我们正在尝试在包含以下代码类型的产品上运行它

  • Javascript
  • VBScript
  • XML
  • C#
  • VB.net
  • T/SQL

现在我们已经运行它来扫描除 T/SQL 代码之外的所有代码。

此 TSQL 代码与所有其他代码位于同一目录下,但没有特定的 Visual Studio 项目。

我们能够在 SQL 上运行扫描的唯一方法是使用标准的 sonarqube 运行器,但这会导致在我们的仪表板上创建一个新产品。

任何想法或建议。

【问题讨论】:

    标签: sonarqube sonarqube-scan sonar-runner


    【解决方案1】:

    目前,如果您希望分析 TSQL 文件并将其显示在与其他代码相同的 SonarQube 项目下,则需要从 MSBuild 项目中引用它。

    有几种方法可以做到这一点:

    1) 使用如下所示的 sn-p 在现有项目之一中包含 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>
    

    【讨论】:

      猜你喜欢
      • 2020-08-07
      • 2021-12-27
      • 2017-04-27
      • 2016-05-11
      • 2018-05-12
      • 2019-10-22
      • 2018-03-17
      • 2017-08-17
      • 2018-01-26
      相关资源
      最近更新 更多