Code Contracts for .NET

Microsoft DevLabs Free

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.

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

by zyrconium | May 28 2014

Uninstalled 1.5 from Add/Remove Programs. Deleted Code Contracts folder from Visual Studio Extensions folder. But it still shows as installed in Visual Studio. Tried to search in registry. No luck. Where else can I look?

by Jiří Zídek | May 26 2014

Failed to upgrade from 1.5 to 1.6 - installation passes, but VS2013U2 RTM sees still V1.5 and notifies me about update, loop closes here. Unistalling 1.5 is always gray (running VS as admin or not)...
Generally without stable Editor Extensions usability is crippled.

Unfortunately cant get rid of 1.5.60911.10 in Tools/Extensions/Installed/All; in Add/Remove it does not exists and folder suggested is deleted. Still appears in VS and still wishes to upgrade in Notifications....

by Espen- | May 25 2014

Jiří Zídek:
Uninstall from Add/Remove programs
Delete folder "CodeContracts"
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\CodeContracts

Install again. Enjoy :)

by stupidservice | April 03 2014

Build performance degradation kills all the good things in this solution.

by Viacheslav - Ivanov | March 14 2014

Need a new releases!

by Francesco Logozzo | February 13 2014

Hi, CC should work with VS2013 without any problem.
Try to uninstall and reinstall?

by FiLCoN | January 21 2014

Not working in VS 2013

by GardenMusic | December 12 2013

It's Dec. 12, 2013. I have VS 2008 with Framework 3.5.

I'd like to use Code Contracts so I'm trying to install the dll that is meant for 2010/4.0 that EVERWHERE I read it says it will work with VS 2008. BUT, the only download I can find is this .VSIX file and VS 2008 will not open it, nor can I find anything that will.

All links I find lead back to this page. So I'm about to give up on using Code Contracts with VS2008 and go back to Debug.Assert. I'd sure appreciate a way to avoid that!!!



by Aleksandr Vishnyakov | November 27 2013

Great tools! When will be released version with Visual Studio 2013 RTM full support?

by Lennox22 | November 22 2013

I previously used Code Contracts back in 2010 and 2011 (with Pex). Worked well. Good concept especially linked with Pex (aka Digger). After upgrading to VS2013, I tried to use Code Contracts on a new project, however after installing, it completely crashes VS2013 Premium - everything is broken, all docked windows are showing exception messages. Extensions are failing to load. Eventually VS "stops" according to Windows. The solution is to repair the VS2013 installation. I will not install this again - especially since PEX is not supported in VS2013.

by John Crim | November 04 2013

Great concept, decent implementation. It's good enough that I've chosen to standardize my dev team on it; and I haven't seen anything comparable in any other programming environment. The concept is definitely 5 stars, but the implementation is 3 stars IMO:

It does have a few bugs I've had to work around, it isn't open-sourced, and it significantly slows down build time (by 10x or more), even with static analysis disabled. The build time is a drag in productivity - C# normally builds so blazingly fast, that dev/test/fix cycles are fast and uninterrupted. But with CC enabled, builds are slow enough that you look for something else to do for a few seconds.

I've found the static analysis to not be worthwhile - it might be worthwhile for new projects starting from the ground up, but it takes a lot of extra work to satisfy in my experience.

But the ability to concisely specify a contract, and leverage it across libraries and documentation is definitely worthwhile.

by Markus.Hanke | October 22 2013

After a while, one is wondering, how one could write projects without this tool.

(pl. add a link to the release notes here, where the download is)

by Kevin_Schilling | September 08 2013

by Vrane | September 05 2013

Code Contracts doesn't work with Resharper :( Any plans for supporting R#?

by AceHack | August 17 2013

by David P. McCarter | August 16 2013

I have installed it twice and I keep getting an error saying I need to install CCRewrite. How come?


by cerebrate | June 28 2013

Absolutely excellent and highly recommended. Getting into the contracts way of things has improved both my productivity and my mental code models enough that I wouldn't code without them, these days.

(Now if only there was a package that would work on the VS 2013 Preview...)

by Dorgaliser | June 26 2013

Does not working with VS 2013 Preview :(

by carbon twelve | April 14 2013

Absolutely excellent. I use code contracts extensively and they have added value in discovering bugs (by being "debug.assert" on steroids, and useful for static analysis), preventing bugs (by making it painless to provide brilliant documentation for you methods and types, so other devs easily know what a method/type supports and what it doesn't), and accelerating the resolution of bugs (with the rewriter turning contracts into assertions, you catch issues usually much closer to where the bug actually occurs, than where it actually starts causing damage -- like where an exception is thrown; also, so often we will know "okay, this bug is because this method doesn't handle the case where p=5 correctly. But we know must read around the code a bit because we've got no idea if this is a bug in the method and it /should/ handle p=5, or it's a bug in the caller which shouldn't ever /pass/ p=5 -- we never ask these questions with methods documented with code contracts).

by michael_volz | April 12 2013

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

1 - 20 of 28 Items