首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SonarScanner用于MsBuild扫描

SonarScanner用于MsBuild扫描
EN

Stack Overflow用户
提问于 2018-09-14 12:16:42
回答 1查看 493关注 0票数 1

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

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

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

此TSQL代码位于与所有其他代码相同的目录下,但没有特定的visual studio项目。

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

任何想法或建议。

EN

回答 1

Stack Overflow用户

发布于 2018-09-18 18:43:29

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

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

1)使用如下代码段将TSQL文件包含在一个现有项目中:

代码语言:javascript
复制
<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的MSBuild目标一起工作。下面的模板适用于扫描仪的v4.3,并且应该也适用于最近的早期版本。

代码语言:javascript
复制
<?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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52331831

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档