visual-studio 如何配置 MSBuild 以仅在发布版本上执行某些任务?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/532003/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 10:08:49  来源:igfitidea点击:

How to configure MSBuild to do some tasks only on release builds?

visual-studiomsbuild

提问by Jader Dias

I just learnedabout how to include FxCop on a build. But it's slow and I want it to be done just only on release builds. Is there any way to configure that?

刚刚了解了如何在构建中包含 FxCop。但它很慢,我希望它只在发布版本中完成。有什么办法可以配置吗?

回答by Julien Hoarau

Check the configuration condition.

检查配置条件。

<Target Name="AfterBuild" Condition="'$(Configuration)' == 'Release' ">

  <FxCop TargetAssemblies="@(OutputAssemblies)"
       RuleLibraries="@(FxCopRuleAssemblies)" 
       DependencyDirectories="$(MSBuildCommunityTasksPath)"
       FailOnError="False"
       ApplyOutXsl="True"
       OutputXslFileName="C:\Program Files\Microsoft FxCop 1.32\Xml\FxCopReport.xsl"
       DirectOutputToConsole="true"/>
</Target>

回答by Gerrie Schenck

Haven't tested this but I think it should be something along the lines of:

尚未对此进行测试,但我认为它应该是以下内容:

<Target Name="MyTarget" Condition="'$(FlavorToBuild)'=='Release'">
   ...do release specific stuff...
</Target>

回答by ThorHalvor

Add a condition in the .msbuild script. Only execute the FxCop task if Configuration is "Release" not f.ex when it is "Debug"

在 .msbuild 脚本中添加条件。仅当 Configuration 为“Release”时才执行 FxCop 任务,而不是在“Debug”时执行 f.ex