Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code Contracts support in Visual Studio Express 2013

I've been developing a C# project in Visual Studio Express 2013 and came across Code Contracts for .NET languages. Impressed by their brevity and the static analysis tool that came with them, I started using them in my code base. However, when I attempted to run my program, I was met by an error message similar to the one found in this SO thread, i.e.

...An assembly (probably "<my project>") must be rewritten using the code contracts binary rewriter (CCRewrite) because it is calling Contract.Requires and the CONTRACTS_FULL symbol is defined. Remove any explicit definitions of the CONTRACTS_FULL symbol from your project and rebuild...

Guides suggest that to fix this, I have to enable Code Contracts from my project's Properties page, but a Code Contracts Properties entry is nowhere to be found in Express.

Some MSDN forum threads seem to indicate that all the tooling for Code Contracts is included in the Express version, but the Code Contracts Properties page is not. This seems to be the case, as I was able to run my project in VSE 2013 only after enabling Code Contracts with a copy of Visual Studio 2012 Ultimate I acquired from my university before graduating.

Is there really no way to work with Code Contracts in Visual Studio Express except by modifying the project files either manually or with a paid version of Visual Studio? If this is the case, I am extremely hesitant to use them at all, since my company is unlikely to purchase VS licenses. Futhermore, it seems extremely odd that Microsoft would attempt to proliferate this new and superior verification paradigm but then restrict it to paying customers only.

like image 826
Matt Kline Avatar asked Jul 14 '14 04:07

Matt Kline


2 Answers

You can probably use the new VS Community 2013, as long as you meet the licensing requirements: http://www.visualstudio.com/en-us/visual-studio-community-vs

Here’s how Visual Studio Community can be used in organizations:

An unlimited number of users within an organization can use Visual Studio Community for the following scenarios: in a classroom learning environment, for academic research, or for contributing to open source projects.

For all other usage scenarios: In non-enterprise organizations, up to 5 users can use Visual Studio Community. In enterprise organizations (meaning those with >250 PCs or > $1 Million US Dollars in annual revenue), no use is permitted beyond the open source, academic research, and classroom learning environment scenarios described above.

It's basically VS 2013 Professional for free so you can install the code contracts extension.

like image 183
Nelson Rothermel Avatar answered Sep 20 '22 14:09

Nelson Rothermel


The problem is your edition of Visual Studio. You are running Visual Studio 2013 Express edition, as you stated. In order to use the binary re-writer from within Visual Studio, you need to install the Code Contracts extensions. These you can download from Microsoft's Research in Software Engineering (RiSE) site, which is packaged as a Windows Installer.

The installer installs the binary re-writer that is required, as well as a bunch of Visual Studio extensions. Unfortunately, Code Contracts states in their manual on page 40 that they don't support the various Visual Studio Express editions. You'll need to at least have Visual Studio 2013 Professional edition in order to use the Code Contracts binary re-writer extension from within Visual Studio, and in order to see the Code Contracts tab on the project properties window.

Code Contracts performs assembly re-writing as a post-build step. Meaning, Visual Studio first compiles the .NET code as it normally would. But, when using Code Contracts and enabling the right options on your project (assuming the VS extensions are installed—which you can't do in Express editions), then the binary re-writer is called for you by Visual Studio after the normal compilation process.

Instead, after compiling your program, you'll need to manually run the ccrewrite program installed by Code Contracts on the compiled assembly (and all dependent assemblies) to 're-write' your assemblies, which will add in all the Code Contract checking information. See the Code Contracts documentation (also available on the RiSE website) for information on how to do this.

like image 28
fourpastmidnight Avatar answered Sep 18 '22 14:09

fourpastmidnight