January 12, 2012
If you decided long ago that you weren’t going to bother trying Code Contracts because you didn’t have Visual Studio Premium edition or higher and thus couldn’t take advantage of static checking, then your wait is finally over.
Code Contracts 1.4.41228.0 was recently released, along with some great news: The Code Contracts static checker is now available for all editions of Visual Studio (excluding Express).
On a sad note, it seems as though Code Contracts will remain in DevLabs through the next Visual Studio cycle.
But to end on a brighter note, apparently the team is still trying to make it an official product.
From the forum announcements section:
We are trying to make the case for Code Contracts to be included in Visual Studio as an official product. Please send us your feedback as soon as possible, especially if you have any details about how exactly it has helped your development process.
So start using it and send them all of your success stories!
Here are some links to get you started:
Editor Extensions (Optional)
September 13, 2009
Microsoft Dev Labs has released a new version of Code Contracts. (For more information about Code Contracts in the .NET Framework 4.0, see System.Diagnostics.Contracts and this article). If you haven't yet, I highly recommend installing the latest Code Contracts release. If you're using Visual Studio 2008 then you'll also get a shiny new tab in your project's Properties window.
Figure 1: Code Contracts tab in Visual Studio 2008 project Properties window
Along with the latest features is a new tool that adds documentation for Code Contracts to an assembly's XML documentation file. The latest release also includes a Sandcastle patch that allows the vs2005 style to include the code contract documentation within an expandable Contracts section, as shown in the following screenshot.
Figure 2: Example Sandcastle output with Contracts section
The following blog post describes how you can patch Sandcastle so that it uses Code Contracts in XML documentation files. The author chose to use DocProject to automate the build process, but I suspect that it will work with or without any automation tools for Sandcastle.
Note that I've tested this procedure with success in Visual Studio 2008 standard edition.
Just don't forget to create a new DocProject or DocSite project after applying the Sandcastle patch. You can use the Import Topics and Settings step in the New Project Wizard to copy over the important stuff from an existing project if you'd like.
On a side note, I think this also about ruins my ContractN project ;). I've abandoned it anyway, so I'll be doing the honorable thing and will close down the ContractN project on CodePlex at some point (to help keep CodePlex clean - just doin' my part). I'll continue to host the code on my blog in case anybody's interested in learning how to use Context-Bound Objects, in some form or another.