开发者

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

开发者 https://www.devze.com 2023-01-10 15:30 出处:网络
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 开发者_Python百科parameters, to disable this?

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 开发者_Python百科parameters, to disable this?


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.


The following should do it:

MSBuild ... /p:RunCodeAnalysis=false


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消