views:

177

answers:

2

Here, we run a set of Visual Studio 2008's CA rules both locally and on the build server. In order to check in, our CA rules must match the servers policy. However, I work on a large solution with several projects. Building the project in release mode takes a long time with the CA rules enabled, but this is necessary when creating or editing unit tests. This makes working with unit tests a painful task. What I'd like to do is to have a quick way (quicker than going through all projects to disable CA) to disable the CA rules during development, and then re-enable them on before checking in. Does anyone know if this is possible?

+1  A: 

The project file (*.csproj for C#) contains an element that controls if Code Analysis will be run - <RunCodeAnalysis>true</RunCodeAnalysis>. (You can see this by opening the project file in a text editor, or Unloading the project in Visual Studio and then selecting Edit.)

You could write a script (e.g. using PowerShell) that would iterate through all of the project files, select the above element with an XPath, and toggle the value of it (i.e. true to false and vice-versa).

This question could be of use.

Graham Clark
+1  A: 

I usually create a "Debug No FxCop" build configuration at the solution level for this, with the only difference between the within-project configurations being the RunCodeAnalysis property that Graham has already mentioned. Using a build configuration for this will allow you to avoid reloading your solution when you want to switch between CA and non-CA modes.

Nicole Calinoiu