Code Contracts for .NET


Code Contracts are static library methods used from any .NET program to specify the code’s behavior. Runtime checking and static checking tools are both provided for taking advantage of contracts.

(49) Review
Visual Studio
2013, 2012, 2010
Download (121,357)
E-mail Twitter Digg Facebook
Add to favorites
Reviews (49)
Sign in to write a review
Sort by:

by darkmaku | April 10 2015

good tool!!! but i wish code contracts for VS 2015 xd

by Roy Mayfield | March 29 2015

Guys, these extensions are appreciated more than you'll ever know. YOU are unsung heroes. This pattern will no doubt grow across all aspects in computing. You have allowed us to prevent* bugs at code-time, *before* unit testing...

EDIT: I think the underlying neat synergy here is that as developers code Contract statements, it makes them *think about states, contexts, and very likely discover possible but unhandled states*. That, by itself, is fantastic ;)

There is no silver bullet, but this, combined with TFS check-in rules... = ? I don't know man... ;)

I bet a nickle at least one office conflict will be prevented (rather than resolved) as a result of this. And that is almost as good as saving a life ;) Kudos guys.

Roy Mayfield
Enterprise Architect

by Borchin | March 14 2015

by Yatajga | February 20 2015

by michael_volz | February 06 2015

Please, please, please make a version for Visual Studio 2015!

Not having Code Contracts when using Visual Studio 2015 is really awful!

Excellent tool! I wish more people would know about it.

by Ash-Ash | February 04 2015

Great tool. Please let us know when to expect a V2015 version.

by Matt Hickford | January 05 2015

Great but please update this for Visual Studio 2015 as soon you can.

by Igorbek | December 06 2014

There's a NuGet package of standalone version of CodeContracts for MSBuild (could be used for CI such as Azure Kudu) -

by IT-Marky | November 15 2014

This is a great project but I'm affected by the installer issues, too - after all four or five installations since the first time I installed CodeContracts I had to clean up the

C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\CodeContracts

directory. Uninstalled the old version first, then installed the new; like now there are two folders 1.7.10908.11 and 1.7.11106.10 of which I have to delete the former older one. Maybe you should explicitly delete the folder from within the MSI uninstall sequence. The files that get left behind and might not be authored for proper removal are:


It's a bit unnerving :-)

by Francesco Logozzo | November 15 2014

hmmm I saw the problems with installation on one of my machine too. Updating to VS2013 v4 solved the issue.

Not sure what it is causing it, on other machines everything went very well.

You can try the suggestion from Miha Markic below otherwise.


by Myauz | November 07 2014

Installer frequently breaks between versions. You'd think "Research in Software Engineering" could figure out how to build a working installer. It doesn't build a lot of confidence, really. Its benefits aren't worth my struggles in updating it or dealing with how it occasionally breaks VS.

by Charlie Holland | October 23 2014

Full of great promise. Unfortunately it doesn't deliver. Static code analysis does absolutely nothing in VS2013 and the documentation is so inconsistent with the UI that it's impossible to work out where the problem may lie.

by Rene Damm | October 03 2014

Same problem. VS2013 is completely unusable even after uninstalling Code Contracts again. All kinds of stock VS functionality (like the Solution Explorer) doesn't load anymore.

by Fabien Launay | September 24 2014

My VS2013 don't start after update with V 1.7.10908.11 and devenv /resetsettings don't works also.

by lostmsu | September 23 2014

Please, add support for VS 14

by NLundberg1 | September 22 2014

The upgrade problems from version 1.5 to 1.6 seam to exist when upgrading from 1.6.60617.15 to 1.7.10908.11 as well.

by TomEnglert | September 21 2014

This tool enhances code quality and stability so much that it's really worth the longer build time.

by Miha Markic | August 19 2014

As some others reported, great concept but I am stuck with 1.5 on VS2013 as well. Duh.
Update: as suggested before, deleting C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\CodeContracts and reinstallation did the trick.

by Doug Stichler | July 30 2014

Anywhere to get the older versions?

by Тridy | July 28 2014

I decided to give it another try after last used in VS2010.
I tried to create a small 4.5.1 solution in VS2013 with a library and a console project. With Code Contracts it takes at least 3 times longer time to build and analyze.

BTW, I believe it was supposed to be part of 4.0. Why is it still a separate downloadable tool?

1 - 20 of 49 Items