Skip to content
Source code for the CodeContracts tools for .NET
C# C++ Visual Basic C XSLT TeX
Branch: master
Clone or download
Latest commit 7255a95 Mar 12, 2017
Type Name Latest commit message Commit time
Failed to load latest commit information.
.nuget Update to NuGet 2.8.6 Aug 18, 2015
Common Fix all remaining line endings Sep 1, 2015
Demo Fix all remaining line endings Sep 1, 2015
Documentation Fix all remaining line endings Sep 1, 2015
ExperimentalTools Fix all remaining line endings Sep 1, 2015
Foxtrot Merge remote-tracking branch 'microsoft/master' into internal/master Sep 22, 2016
Microsoft.Research It would help if the MSBuild15 targets were actually part of a feature. Mar 8, 2017
Microsoft.VisualStudio.CodeTools Removed build ouptut from source control repository. Jan 8, 2016
System.Compiler Merge pull request #452 from mnkraus/FixAssemblyRefs Jul 26, 2016
.gitattributes Add initial .gitattributes Jun 14, 2015
.gitignore Add .vs to .gitignore Mar 8, 2017
CCR.sln Initial checkin Jan 6, 2015 Add 'contract issue' to the list of labels. Jun 24, 2015
CodeContracts.sln Maintainability: Remove experimental projects and related tests: Dec 31, 2015
CodeContracts10.vsmdi Initial checkin Jan 6, 2015
FoxtrotTestRun.testrunconfig Fix for unit tests Jun 25, 2015
LICENSE.txt Re-save all text files with proper line endings Jun 14, 2015
Local.testsettings Initial checkin Jan 6, 2015 Improved formatting of "provided tools" list in README. Mar 24, 2016
TraceAndTestImpact.testsettings Re-save all text files with proper line endings Jun 14, 2015
appveyor.yml Enable foxtrot tests Feb 5, 2016
build.bat Propagating build script error codes all the way to the top level scr… Aug 2, 2015
buildCC.bat Making sure to restore packages from the top-level solution before bu… Aug 2, 2015
oob.sln Initial checkin Jan 6, 2015


Join the chat at

Source code for the CodeContracts tools for .NET

Code Contracts provide a language-agnostic way to express coding assumptions in .NET programs.

The contracts take the form of pre-conditions, post-conditions, and object invariants. Contracts act as checked documentation of your external and internal APIs. The contracts are used to improve testing via runtime checking, enable static contract verification, and documentation generation. Code Contracts bring the advantages of design-by-contract programming to all .NET programming languages. We currently provide three tools:

  1. Runtime Checking. Our binary rewriter modifies a program by injecting the contracts, which are checked as part of program execution. Rewritten programs improve testability: each contract acts as an oracle, giving a test run a pass/fail indication. Automatic testing tools, such as Pex, take advantage of contracts to generate more meaningful unit tests by filtering out meaningless test arguments that don't satisfy the pre-conditions.
  2. Static Checking. Our static checker can decide if there are any contract violations without even running the program! It checks for implicit contracts, such as null dereferences and array bounds, as well as the explicit contracts.
  3. Documentation Generation. Our documentation generator augments existing XML doc files with contract information. There are also new style sheets that can be used with Sandcastle so that the generated documentation pages have contract sections.

Quick Links

Building from source

For working on the project, open CodeContracts.sln and build.

To create the installer and the nuget package, just run buildCC <version>.

We use the convention:

  • CC major version = 1.9.1
  • CC minor version = {month}{day}.{buildInTheDay}

For instance, the 10th build on July 16 would be run as follows:

buildCC 1.9.10716.10
You can’t perform that action at this time.