- Using the FxCop GUI
- Repairing the Errors
- Ignoring the Rules
- Employing FxCop During a Build
- Creating New Rules
- Bottom Line
Employing FxCop During a Build
Let's say that you don't want to have to build the project and then execute FxCop separately. It's possible to overcome this problem by adding FxCop directly to the application's build process because FxCop also comes in a command-line version. The FxCop documentation shows how to add FxCop as an external tool to the Visual Studio .NET interface, but this means you'll still have to execute it separately.
To make the process automatic, follow these steps:
Choose Project, Properties to display the application's Property Pages dialog box.
Select Common Properties and then Build Events. Click the ellipsis (...) next to the Post-build Event Command Line property. You'll see a Post-build Event Command Line dialog box similar to the one shown in Figure 3.
At this point, all you need to do is type instructions for using FxCop. Here are some basic instructions that work well with the current version:
Figure 3 Add FxCop to the build process so it executes automatically.
CD "\Program Files\Microsoft FxCop 1.23\" fxcopcmd /f:"$(TargetPath)" /c /r:rules
This entry tells the compiler to change directories to the FxCop directory and then use the command-line version of FxCop to check the application. The /f: command-line switch tells the location of the application. You can substitute the $(TargetPath) macro in quotes ("") as shown in the example to provide FxCop with the location of your code. Now, every time you build the application, FxCop will also run and display any correctness errors in your code.