Visual Studio 项目中 AfterBuild 任务的顺序...?
我在 Visual Studio 项目中定义了多个具有不同条件的 AfterBuild - 任务:
<Target Name="AfterBuild" Condition="'$(Configuration)'=='FinalBuilder'">
<Message Importance="high" Text="--- AfterBuild for FinalBuilder ---" />
</Target>
<Target Name="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
<Message Importance="high" Text="--- AfterBuild for MvcBuildViews ---" />
</Target>
但如果条件匹配,则仅执行最后一个任务。如果我选择 FinalBuilder-Configuration,则 AfterBuild 任务将被忽略并且不会执行。如果我更改项目文件中目标的顺序(Condition="'$(Configuration)'=='FinalBuilder'" 作为最后一个),则将执行 FinalBuilder-Configuration 的 AfterBuild,但忽略 MvcBuildViews 的 AfterBuild。
目标的顺序重要吗?是否只考虑最后一个 AfterBuild 任务?或者如何定义具有不同条件的不同 AfterBuild 任务?
谢谢
康拉德
I have defined several AfterBuild - Tasks in my Visual Studio project with different conditions:
<Target Name="AfterBuild" Condition="'$(Configuration)'=='FinalBuilder'">
<Message Importance="high" Text="--- AfterBuild for FinalBuilder ---" />
</Target>
<Target Name="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
<Message Importance="high" Text="--- AfterBuild for MvcBuildViews ---" />
</Target>
But only the last one is executed if the condition match. If I choose the FinalBuilder-Configuration, the AfterBuild tasks is ignored and not executed. If I change the order of the Targets in the project files (Condition="'$(Configuration)'=='FinalBuilder'" as last one), the AfterBuild for FinalBuilder-Configuration is executed but the one for MvcBuildViews is ignored.
Is the order of the target important? Is only the last AfterBuild task taken into account? Or how can I define different AfterBuild tasks with different Conditions?
Thanks
Konrad
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
唯一的第二个被执行,因为它被重新定义了。请参阅 MSDN(在项目文件章节中声明目标)。
您应该在项目文件中仅使用一个 AfterBuild 目标,如下所示:
编辑:
或者使用 CallTarget 任务:
The only second one is executed because it was redefined. See MSDN (Declaring targets in the project file chapter).
You should use only one AfterBuild target in your project file like this:
EDIT:
Or use CallTarget task:
如果您确实需要运行多个 AfterBuild 任务(例如,如果每个任务需要不同的输入和输出集,则可能是这种情况),您可以使用 DependsOnTarget 简单地使 AfterBuild 依赖于所有这些任务:
如果您需要约束它们的顺序,只需使用
DependsOnTargets="AfterBuild1"
使 AfterBuild2 依赖于 AfterBuild1。If you really need to run multiple AfterBuild tasks (this may be the case for example if you need different Input and Output sets for each task) you can use DependsOnTarget to simply make AfterBuild depend upon all of them:
If you need to constrain their order, just make AfterBuild2 depend on AfterBuild1 with
DependsOnTargets="AfterBuild1"
.