views:

269

answers:

2

.NET 4 introduced Code Contracts as a new feature. I'd like to use CC, but provide files that can still run in 3.5 SP1. Is that possible? Can I only use parts of the new functionality? Apparently it is possible to have CC only do static checks without being included in the binary files, is that correct?

I'm aware CC was available for 3.5 as separate module, is this a feasible workaround in case I can't use the 4 version of CC? Is there a difference in the feature set?

+1  A: 

I'd like to use CC, but provide files that can still run in 3.5 SP1. Is that possible?

You can't use .NET 4.0 CC but you can use Microsoft.Contracts.dll which is the 3.5 CC assembly.

Apparently it is possible to have CC only do static checks without being included in the binary files, is that correct?

Yes. The premium edition includes the static checker, but you need VS2008 Team System or VS2010 Premium/Ultimate to use Code Contracts Premium Edition.

I'm aware CC was available for 3.5 as separate module, is this a feasible workaround in case I can't use the 4 version of CC?

Yes it is still available. Get it from http://msdn.microsoft.com/en-us/devlabs/dd491992.aspx

GiddyUpHorsey
+2  A: 

Yes, you can use Code Contracts with .NET 3.5 (but you're wise to develop with Visual Studio 2010 so you get tooling support). Just download the MSI from the Code Contracts web site, install and copy the DLLs from C:\Program Files (x86)\Microsoft\Contracts\Contracts\v3.5 to your solution and reference Microsoft.Contracts.dll explicitly in all projects that make use of it.

If you're bound to an earlier version of Visual Studio than 2010, or a version of 2010 that doesn't have Code Contract support, you can execute ccrewrite.exe, ccrefgen.exe and ccdocgen.exe (located in C:\Program Files (x86)\Microsoft\Contracts\Bin) from the command line as a post build event.

asbjornu
Code Contracts does work with VS2008 Team Edition (though not any of the other editions of VS2008)
Jeffrey Cameron