Lieven Cardoen
Lieven Cardoen

Reputation: 25979

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?

Upvotes: 6

Views: 1931

Answers (3)

Gleb Sevruk
Gleb Sevruk

Reputation: 534

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.

Upvotes: 1

mnemosyn
mnemosyn

Reputation: 46331

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.

Upvotes: 8

Ade Miller
Ade Miller

Reputation: 13753

The following should do it:

MSBuild ... /p:RunCodeAnalysis=false

Upvotes: 2

Related Questions