Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use .NET 4 Code Contracts and remain compatible with .NET 3.5?

.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?

like image 795
mafu Avatar asked Apr 08 '10 08:04

mafu


People also ask

Do I need NET Framework 3.5 if I have 4?

So to answer your question you only need both if your application uses features from both or altenatively you have separate web applications that use . NET 3.5 and . NET 4.0.

Does installing .NET 4.0 will affect existing .NET applications?

No, they can exist alongside eachother. Just like with previous versions. In fact, 4.0 uses completely different directories to store its assemblies in.

Is .NET 4 backwards compatible?

NET Framework 4.5 and later versions are backward-compatible with apps that were built with earlier versions of the . NET Framework. In other words, apps and components built with previous versions will work without modification on the . NET Framework 4.5 and later versions.

Is .NET framework 3.5 still supported?

NET Framework 4.6. 2 or later by April 26, 2022 to continue receiving technical support and security updates. . NET Framework 3.5 SP1, beginning with Windows 10 version 1809 and Windows Server 2019, is a standalone product and receives 5 years of mainstream support followed by 5 years of extended support.


2 Answers

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

like image 178
John Mills Avatar answered Oct 29 '22 11:10

John Mills


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.

like image 24
Asbjørn Ulsberg Avatar answered Oct 29 '22 10:10

Asbjørn Ulsberg