Compiler Warnings, XML Comments, And Code Analysis

In Visual Studio, missing XML comments and code analysis violations generate compiler warnings. In the beginning of a development project, XML comments are typically not written, and code analysis violations may not yet have been taken care of. This causes a large number of compiler warnings to be generated by Visual Studio - often several hundreds.

In at least a couple of cases, I've helped other developers troubleshoot bugs in their application where it turned out that the clue and solution to the problem was available as a 'real' compiler warning. However, hundreds of XML comment or code analysis warnings had caused the developer to stop looking at compiler warnings at all, so the 'real' compiler warning was drowned out by all those other warnings. Even though the solution to the bug was right under the developer's nose, hours or even days was lost troubleshooting.

This obviously diminishes the value of compiler warnings, which leads some developers to turn off code analysis or XML comments. You can, however, get the best of both worlds:

To avoid the issue of massive amounts of compiler warnings, and to increase compilation speed while I'm developing, I disable both code analysis and XML comments for Debug builds, and enable them for Release builds.

When I'm developing, I do this in the Debug configuration until my code is ready (usually determined by all unit tests passing). Since both code analysis and XML commants are not enabled in my Debug configurations, 'real' compiler warnings will show up immediately without being drowned out by all the other warnings. When the code is ready, I change to the Release configuration, where both code analysis and XML comments are enabled, and I polish off the code in that configuration until I have no more warnings.

This simple trick may save you some time, and when code analysis is turned off in the Debug configuration, your code will also compile a lot faster.