Tuesday, March 12, 2013

Turning on Visual Studio 2010 Code Analysis in a machine-independent manner

So you want to turn on Visual Studio 2010’s Code Analysis option but someone on the team rightly points out that this adds a machine specific directory to the .csproj file. Machine specific settings shouldn’t be in a shared project file (.csproj is typically shared).

Visual Studio 2010 uses MSBuild. MSBuild has lots of built in (“reserved”) properties. For instance, $(TEMP) will evaluate to the environment variable for temp.

Fortunately Visual Studio defines a property $(DevEnvDir) that, with slight modification, can point to the ruleset file required for Code Analysis in a machine-independent manner.

References

MSBuild Reserved Properties

Visual Studio Integration with MSBuild

Macros for Build Commands

No comments :

Post a Comment