How will using code contracts in my web project affect deployment?
If code contracts are used in the application, then do we need to install something (from the Code Contracts package) on the production server, for example, put assemblies in the GAC or the contract contracts installation package on the production server?
Or just putting the libraries in the bin folder will work?
a source to share
It is enough to put them in the bin / folder.
Something like this a few weeks ago, I downloaded a trial for the charting engine, put the .dll in the lib folder, and added a link to them in my web project.
We used the Publish option in Visual Studio when we deployed the website so we get a nice, clean build to upload (we now have a build server).
This all worked great until we decided to buy the component, I installed it and added all the assemblies that we moved / installed in the GAC. I took the assemblies and put them in our lib folder and added the links again.
Everything we are working on until we decided to publish an update for the project with new assemblies of diagram engines. The site stops working !:(
After a short time of debugging, we discovered that the error was due to the fact that the new .dlls for the graphics engines were not sent to the bin folder as they were in the GAC. But when we published our server, they weren't there, so to fix the problem we just copied them and everything worked like a charm again.
a source to share
From the Code Contracts site linked to your question:
Contracts act as validated documentation of your external and internal APIs. Contracts are used to improve testing through runtime validation, enabling static validation of contracts, and generating documentation.
Correct me if I'm wrong, but I think code contracts are only for design time support. Therefore, it is assumed that you disable them when compiling assembly intended for deployment / production.
a source to share
I realize this is an older thread, but the question still remains true ...
Assuming .NET 4.0, the System.Diagnostics.Contract classes are already included in mscorlib.dll. Thus, all you need to install is the .NET 4.0 runtime.
You will need to install the CodeContracts package for dev machines and any other machines that will compile your pre-IL binaries (i.e. via VisualStudio, msbuild, using csc.exe - C # compiler, etc.). Several .exe are included in this installation package. One of them is "ccrewrite.exe". This is IL rewriting code that injects IL code into your assemblies after the compiler has completed. Please note that ccrewrite and the .NET compiler you use for whatever language you use are not bundled, linked , or exchanged any dependencies.
Once your binaries are compiled, there is no need to install or deploy anything to any of the servers your code will run on. This value is independent of the parameters that you configured in the project settings:
- using Runtime Contract Checker
- Using static contract validation
- configured to build CodeContract link collections (you don't need to deploy them either).
- and etc.
CodeContract referenced assemblies are only used when you need to expose your contracts to a library / API that is outside of your solution and static checking is enabled for that project. You also don't have to link to them directly, and you don't need any post-build step to copy them to any bin folder (except for the case I just mentioned about exposing them to another library / API).
NTN
a source to share