Having started using Code Contracts on our project, build
time increased dramatically.
Even with “Check in Background” turned on – the build is
still slow and causing major problems:
- *.pdb and *.dll files sometimes become locked
- Error 1 The command "C:\Program Files (x86)\Microsoft\Contracts\Bin\ccrewrite" "@Application1ccrewrite.rsp"" exited with code -1 (even from unit tests)
- Process “ccheck.exe” just hang and consume 100% CPU even after build has cancelled
The solution was to do “Clean Solution”, remove all output folders
(sometimes with Unlocker, and that is sic), and do clean rebuild.
It is just unacceptable if I am debugging only one Unit Test
from one specific project to clean and rebuild everything.
There are several ways to disable checking.
Normal way
Project Properties. If you have full control over *.csproj
file you can just uncheck it.
If your team wants to check code contract, you cannot simply disable it in global project properties.
Another drawback is that you need to do it for every
project.
Msbuild way
If you only use build scripts for compilation then it is
simple to pass variable to msbuild:
msbuild .exe "AllBuild.proj" /m:8 /t:build /p:CodeContractsRunCodeAnalysis=false,RunCodeAnalysis=Never,CodeContractsReferenceAssembly=DoNotBuild
Visual Studio and
Msbuild
If you do not want to pass parameters to msbuild or you are
building from Visual Studio, there is a way to suppress static code contracts
check and code analysis.
Using this approach, you will disable it machine-wide.
Notice: each *.csproj file contains <Import
Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />.
It is possible to modify Microsoft.CSharp.targets in a way
it will emulate passing parameters to msbuild
On my PC and.Net 4 full path to *.target and msbuild is "C:\Windows\Microsoft.NET\Framework\v4.0.30319\"
Open “C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.CSharp.targets”
Add new PropertyGroup inside Project like:
<Project>
...
<PropertyGroup>
<CodeContractsRunCodeAnalysis>false</CodeContractsRunCodeAnalysis>
<RunCodeAnalysis>Never</RunCodeAnalysis>
<CodeContractsReferenceAssembly>DoNotBuild</CodeContractsReferenceAssembly>
</PropertyGroup>
...
<!-- About 5k lines bellow... -->
</Project>
All your builds now on your pc (from either MSBuild or
Visual Studio) will skip code and static code contracts analysis, so you do not
need to pass arguments, from Command Line, and all builds will skip analysis.
Note: all assemblies will still be rewritten so you cannot use "Edit And Continue" feature. I hope to find solution to it soon.

Комментариев нет:
Отправить комментарий