How to specify CodeAnalysisRules in MSBuild via commandline
Asked Answered
R

2

5

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

Radiometeorograph answered 23/10, 2009 at 1:21 Comment(0)
C
1

Try this:

msbuild /property:RunCodeAnalysis=true;CodeAnalysisRules=-Microsoft.Globalizati
on#CA1301%3B-Microsoft.Globalization#CA1302
Castanon answered 29/12, 2009 at 19:9 Comment(0)
R
0

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

Radiometeorograph answered 3/1, 2010 at 22:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.