Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way not to let MsBuild run static contract analysis with code contracts?

In my project, static checking is disabled, but still, when I run msbuild.exe with cmd, it starts static checking for each project... Is there a way, with parameters, to disable this?

like image 450
Lieven Cardoen Avatar asked Aug 09 '10 12:08

Lieven Cardoen


3 Answers

This might be a 'little' late, but since I just encountered the same problem and /p:RunCodeAnalysis=false doesn't work for me:

Try msbuild ... /p:CodeContractsRunCodeAnalysis=false.

That works as of Feb. 2011 according to the code contracts documentation and my experience.

like image 100
mnemosyn Avatar answered Nov 28 '22 11:11

mnemosyn


The following should do it:

MSBuild ... /p:RunCodeAnalysis=false
like image 35
Ade Miller Avatar answered Nov 28 '22 13:11

Ade Miller


If you don't 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.

Notice: each *.csproj file contains this: <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />.

For .Net 4.0 msbuild.exe and Microsoft.CSharp.targets path is "C:\Windows\Microsoft.NET\Framework\v4.0.30319\"

Open Microsoft.CSharp.targets Add new PropertyGroup inside Project like:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
...
 <PropertyGroup>  
   <CodeContractsRunCodeAnalysis>false</CodeContractsRunCodeAnalysis>
   <RunCodeAnalysis>Never</RunCodeAnalysis>
   <CodeContractsReferenceAssembly>DoNotBuild</CodeContractsReferenceAssembly>
 </PropertyGroup>
...
<!-- a lot of stuff -->
...
</Project>

Doing so will emulate msbuild command line arguments (i.e /p:CodeContractsRunCodeAnalysis=false,RunCodeAnalysis=Never,CodeContractsReferenceAssembly=DoNotBuild

All your builds now on your pc (either from MSBuild and Visual Studio) will skip code and static code contracts analysis, so you don't need to pass args from Command Line.

like image 28
Gleb Sevruk Avatar answered Nov 28 '22 13:11

Gleb Sevruk