How to specify CodeAnalysisRules in MSBuild via commandline

眉间皱痕 提交于 2020-01-02 04:55:11

问题


I want to be able to specify the Code AnalysisRules in commandline MSBuild (for Code Analysis / FXCOP). The project file would have something like this in it:

<CodeAnalysisRules>-Microsoft.Globalization#CA1301;-Microsoft.Globalization#CA1302</CodeAnalysisRules>

So I would assume that I use something like this:

MSBuild.exe /property:RunCodeAnalysis=true /property:CodeAnalysisRules=-Microsoft.Globalization#CA1301

Which works fine, but when I want to add another rule, it does not like the semi colon:

MSBuild.exe /property:RunCodeAnalysis=true /property:CodeAnalysisRules=-Microsoft.Globalization#CA1301;-Microsoft.Globalization#CA1302

MSBUILD : error MSB1006: Property is not valid. Switch: -Microsoft.Globalization#CA1302

How can I specify more than one rule?

I am happy to reference a file, but I don't want to just change the project files.

Backgroud: I want to create a set of rules for a continuous integration server (Hudson in my case).

Note: I am running Visual Studio 2005


回答1:


Try this:

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



回答2:


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 :)



来源:https://stackoverflow.com/questions/1610938/how-to-specify-codeanalysisrules-in-msbuild-via-commandline

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