MSBuild 条件执行?
我正在使用
例如,
<Target Name="Name">
<MSBuild Projects="" />
<Exec Command="" />
</Target>
我注意到该项目仅根据需要构建,并在运行构建脚本:“跳过目标“CoreCompile”,因为所有输出文件都是最新的”。这很好,但是如何使我的
更新:我已经实现了 gregmac 的建议,但它仍然执行命令,这就是我现在得到的:
<Target Name="Name">
<MSBuild Projects="">
<Output TaskParameter="TargetOutputs" ItemName="AssembliesBuiltByChildProjects" />
</MSBuild>
<Exec Command="" Condition="'@(AssembliesBuiltByChildProjects)'!=''" />
非常感谢任何进一步的帮助。这对我来说是一个症结所在。
感谢您的任何提示。
艾伦
I am building various projects using the <MSBuild Projects="... markup. I am then executing some command line tools after the project is built.
E.g
<Target Name="Name">
<MSBuild Projects="" />
<Exec Command="" />
</Target>
I notice that the project is only built as required and get the following output when the build script is run: "Skipping target "CoreCompile" because all output files are up-to-date". This is great but how do I make my <Exec... commands use the same condition so that they are only run when necessary as well?
Update: I've implemented gregmac's suggestion but its still executing the command regardless. This is what I've got now:
<Target Name="Name">
<MSBuild Projects="">
<Output TaskParameter="TargetOutputs" ItemName="AssembliesBuiltByChildProjects" />
</MSBuild>
<Exec Command="" Condition="'@(AssembliesBuiltByChildProjects)'!=''" />
Any further help is much appreciated. This is a bit of a sticking point for me.
Thanks for any tips.
Alan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您应该能够使用TargetOutputs 参数:
You should be able to use the TargetOutputs parameter:
如果您可以将以下内容添加到每个项目中:
...那么您只需要添加一个属性:
这之所以有效,是因为 Microsoft 的聪明人在 CoreCompile 目标的末尾添加了以下行:
Microsoft.[CSharp|VisualBasic][.Core].targets
(文件名取决于语言和 MSBuild/Visual Studio 版本)。因此,如果您在
TargetsTriggeredByCompilation
属性中指定目标名称,则在CoreCompile
运行时您的目标将运行,而在CoreCompile
运行时您的目标将不会运行被跳过(例如,因为输出程序集相对于代码来说已经是最新的)。If you can add the following to each of your projects:
... then you only need to add a property:
This works because someone smart at Microsoft added the following line at the end of the
CoreCompile
target inMicrosoft.[CSharp|VisualBasic][.Core].targets
(the file name depends on the language and MSBuild/Visual Studio version).So if you specify a target name in the
TargetsTriggeredByCompilation
property, your target will run ifCoreCompile
runs-- and your target will not run ifCoreCompile
is skipped (e.g. because the output assembly is already up-to-date with respect to the code).你问错了问题。
Exec 没有任何条件,但是您可以在 Target 元素上有条件,可以像这样使用。
You are asking wrong question.
Exec does not have any condition, But you can have condition on Target element which can be used like this.
我确实找到了一个满足我需求的解决方案,尽管它可能不是最佳解决方案。
请在此处查看我对其他问题的回答:MSBuild 构建后
谢谢,
艾伦
I did manage to find a solution to fit my needs although it may not be the optimal solution.
See my answer to my other question here: MSBuild Post-Build
Thanks,
Alan