As a software developer and trainer I am often asked what tools can help with ensuring code is written correctly and follows the right development guidelines and best practices. Over time the ideas around coding styles and formatting have changed considerable and Microsoft has released new versions of two extremely useful applications which focus on this topic, one checking code before it is compiled and the other checking code after it has been compiled.

FxCop 1.36 (Homepage)

Last night I was made aware that Microsoft has released FxCop 1.36. This little gem has not been updated in quite some time but is extremely useful. By pointing FxCop to an already compiled .Net assemblies, a code analysis is done which can be extremely revealing and interesting. The resulting HTML report lists all potential code violations and incorrect syntax. The extremely handy part of FxCop is that all errors have a unique identifying code which can be used in the MSDN library to find a description on what the problem means and how to correct it. It also features MSBuild integration and can also be used with continues integration platforms like CruiseControl.Net. FxCop can also be used on ASP.Net Web Project from the command line allowing the same analysis to be done on Website Development and also works on Windows Mobile assemblies.

I also use FxCop to learn more about .Net. The documentation is complete and informative, allowing for a better understanding of how to implement certain features and applying best practices to code. It also promotes code consistency in development teams since the rules engine can be modified and adapted to the guidelines set for each industry. The default rule set is closely tied to the Microsoft Best Practices guidelines and by default already provides single developers an invaluable method of implementing code correctly.

FxCop will not make any changes to code directly, and will only report on results. With the flexible rules engine and wealth of information it provides developers, I would really like to see some out of the box Visual Studio integration in the next version, similar to what is done with TFS. It should however become one of the most important tools used by any .Net developer today.

StyleCop 4.3 (Homepage)

For a long time Microsoft had an in-house tool similar to FxCop, with one important difference, it analysed the code before compiling and is integrated into Visual Studio. As with FxCop, StyleCop provides important insight into the code before it is even compiled, and can also be completed integrated into MSBuild. The net result being that code can be analysed as it's written, ensuring that best practices and coding guidelines are always enforced. I am especially impressed with the heavy weight put on proper commenting guidelines.

I only recently started using StyleCop, but like FxCop it is an important tool in my development toolbox. The importance of proper coding has become more and more of a focus in my own career, and using these tools ensures that code reusability and correctness becomes a core focus during the actual development stages, and can very often assist in avoiding problems when testing and deploying.

I am extremely glad to see Microsoft release these powerful tools to the development world. Feel free to download both application and give them a try on one of your latest projects, you'll be amazed at what you will find needs to be changed.