How to specify CodeAnalysisRules in MSBuild via commandline

落爺英雄遲暮 提交于 2019-12-05 10:15:45

Try this:

msbuild /property:RunCodeAnalysis=true;CodeAnalysisRules=-Microsoft.Globalizati
on#CA1301%3B-Microsoft.Globalization#CA1302
Triple Point

The suggestion by KMoraz only seems to work for a single rule. What I want is to be able to remove multiple rules. I also want to be able to do this for multiple projects.

I have figured out what I needed to do: I maintain one 'rules' file that holds all the exclusions that are to be used for every project. I then reference this file in the project file. So it looks something like this:

The Project file:

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <!--the other project stuff here-->
  <Import Project="X:\Hudson\jobs\bin\DefaultRules.targets" xmlns="" />
</Project>

The exclusion file (DefaultRules.targets):

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <RunCodeAnalysis>true</RunCodeAnalysis>
      <CodeAnalysisRules>-Microsoft.Design#CA2210;-Microsoft.Design#CA1014;-Microsoft.Design#CA2210;-Microsoft.Naming#CA1705;-Microsoft.Globalization#CA1300;-Microsoft.Globalization#CA1301;-Microsoft.Globalization#CA1302;-Microsoft.Globalization#CA1303;-Microsoft.Globalization#CA1306;-Microsoft.Globalization#CA1304;-Microsoft.Globalization#CA1305</CodeAnalysisRules>
   <TreatWarningsAsErrors>`false`</TreatWarningsAsErrors>
  </PropertyGroup>
</Project>

I store the exclusion file on the repository and every solution and project uses it. Pretty neat :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!