Marko Apfel

C#, Architecture, QA, Coach, GIS, ArcGIS, ArcObjects

  Home  |   Contact  |   Syndication    |   Login
  141 Posts | 2 Stories | 69 Comments | 4 Trackbacks

News



Twitter | LinkedIn | Xing

Twitter












Article Categories

Archives

Post Categories

BizTalk

C#

Enterprise Library

SAP

SQL Server

Technologie

Wednesday, November 11, 2009 #

see also Working with Microsoft FxCop

As described in the previous post a custom dictionary could be referenced in a FxCop-call of a target by using the option:

/dictionary:"$(ProjectDir)..\FxCop.CustomDictionary.xml"

But how is it possible to publish this custom dictionary for the Visual Studio integrated code analysis?

This analysis runs an other FxCop.exe than my special FxCop-target. So the custom dictionary which is specified in the FxCop-call of my target is not used.

The solution is very simple. Because every project gets the FxCop-target the information about the custom dictionary could be inserted there.

This is done with the section:

<ItemGroup>
    <CodeAnalysisDictionary Include="&quot;$(ProjectDir)..\FxCop.CustomDictionary.xml&quot;" />
</ItemGroup>

Visual Studio code analysis uses this information. So with one line all projects are satisfied.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Run FxCop as a post build event

Since FxCop 1.36 it is possible to include FxCop in a post-build event.

So FxCop runs after compiling in Visual Studio and allows you directly jumping to the warned line.

 

Description of the command line

In the sample above the command line is

IF $(ConfigurationName) == Debug $(ProjectDir)..\..\..\..\tools\FxCop\FxCopCmd.exe
/console  
/file:"$(TargetPath)" 
/directory:"$(ProjectDir)..\..\..\..\lib\Primary Interop Assemblies" 
/directory:"$(ProjectDir)..\..\..\..\lib\ArcGIS\9.2.0.1324" 
/dictionary:"$(ProjectDir)..\..\..\CustomDictionary.xml"

 

Parameter Description
/console Outputs messages to console, including file and line number information.
/file

Assembly file to analyze.

$(TargetPath) is a makro-variable of Visual Studio which points to the compilation.

Wrap it in quotations to avoid problems with spaces in path names.

/directory

Location to search for assembly dependencies. This parametes could occurs multiple times.

$(ProjectDir) is a makro-variable of Visual Studio which points to the *.csproj-file of the project.

/dictionary

Custom dictionary to allows own abbreviations and own words for syntax checking.

 

Integration as a build target

Integration as an own target

Instead running FxCop as a post build event the using of build targets is a good and since using of Hudson the recommended way.

In the csproj file therefore a new target must included. You could name it De.Esri.FxCop.targets for instance.

Place the call of this target beneath the normal build target.

<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\De.Esri.FxCop.targets" />

And now we need this target. Important is the FxCopCmd-call. Therefore we use the Exec tag.

The whole call must made in one line. Only for documentation purposes every option has a own line.

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <BuildDependsOn>$(BuildDependsOn);FxCop</BuildDependsOn>
        <RebuildDependsOn>$(RebuildDependsOn);FxCop</RebuildDependsOn>
    </PropertyGroup>
 
    <ItemGroup>
        <CodeAnalysisDictionary Include="&quot;$(ProjectDir)..\FxCop.CustomDictionary.xml&quot;" />
    </ItemGroup>
    
    <Target Name="FxCop">
        <Exec Command="..\..\tools\FxCop\FxCopCmd.exe 
/file:&quot;$(TargetPath)&quot;
/dictionary:&quot;$(ProjectDir)..\FxCop.CustomDictionary.xml&quot;
/out:&quot;$(OutDir)..\$(ProjectName).FxCopReport.xml&quot;
/console /forceoutput"
WorkingDirectory="..\..\tools\FxCop\" ></Exec> <Message Text="FxCop finished." /> </Target> </Project>

Because the filesystem ressource parameters could contain spaces (e.g. )Program Files) these parameters must be quoted. Thats why we need the cryptical &quot; there.

Integration as a MSBuild-Community target

John Rayner's Blog

Complex build script run FxCop:

Integrating FxCop into CruiseControl.NET

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati