Visual Studio 项目中 AfterBuild 任务的顺序...?

发布于 2024-12-24 16:55:25 字数 762 浏览 2 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风尘浪孓 2024-12-31 16:55:25

唯一的第二个被执行,因为它被重新定义了。请参阅 MSDN(在项目文件章节中声明目标)。

您应该在项目文件中仅使用一个 AfterBuild 目标,如下所示:

<Target Name="AfterBuild" >
    <Message Condition="'$(MvcBuildViews)'=='true'" Importance="high" Text="--- AfterBuild for MvcBuildViews ---" />
    <Message Condition="'$(Configuration)'=='FinalBuilder'" Importance="high" Text="--- AfterBuild for FinalBuilder ---" />
</Target> 

编辑:
或者使用 CallTarget 任务:

<Target Name="AfterBuild" >
    <CallTarget Condition="'$(MvcBuildViews)'=='true'" Targets="MvcBuildTarget" />
    <CallTarget Condition="'$(Configuration)'=='FinalBuilder'" Targets="FinalBuilderTarget" />
</Target> 

<Target Name="MvcBuildTarget">
    <Message Importance="high" Text="--- AfterBuild for MvcBuildViews ---" />
</Target> 

<Target Name="FinalBuilderTarget" >
    <Message Importance="high" Text="--- AfterBuild for FinalBuilder ---" />
</Target> 

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:

<Target Name="AfterBuild" >
    <Message Condition="'$(MvcBuildViews)'=='true'" Importance="high" Text="--- AfterBuild for MvcBuildViews ---" />
    <Message Condition="'$(Configuration)'=='FinalBuilder'" Importance="high" Text="--- AfterBuild for FinalBuilder ---" />
</Target> 

EDIT:
Or use CallTarget task:

<Target Name="AfterBuild" >
    <CallTarget Condition="'$(MvcBuildViews)'=='true'" Targets="MvcBuildTarget" />
    <CallTarget Condition="'$(Configuration)'=='FinalBuilder'" Targets="FinalBuilderTarget" />
</Target> 

<Target Name="MvcBuildTarget">
    <Message Importance="high" Text="--- AfterBuild for MvcBuildViews ---" />
</Target> 

<Target Name="FinalBuilderTarget" >
    <Message Importance="high" Text="--- AfterBuild for FinalBuilder ---" />
</Target> 
2024-12-31 16:55:25

如果您确实需要运行多个 AfterBuild 任务(例如,如果每个任务需要不同的输入和输出集,则可能是这种情况),您可以使用 DependsOnTarget 简单地使 AfterBuild 依赖于所有这些任务:

  <Target Name="AfterBuild1"
    Inputs="stuff"
    Outputs="stuff">
      <Message Text="Running first after build task."  Importance="high" />
      <Exec Command="stuff" />
  </Target>
  <Target Name="AfterBuild2"
    Inputs="other stuff"
    Outputs="other stuff">
      <Message Text="Running other after build task."  Importance="high" />
      <Exec Command="stuff" />
  </Target>
  <Target Name="AfterBuild" DependsOnTargets="AfterBuild1;AfterBuild2" />

如果您需要约束它们的顺序,只需使用 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:

  <Target Name="AfterBuild1"
    Inputs="stuff"
    Outputs="stuff">
      <Message Text="Running first after build task."  Importance="high" />
      <Exec Command="stuff" />
  </Target>
  <Target Name="AfterBuild2"
    Inputs="other stuff"
    Outputs="other stuff">
      <Message Text="Running other after build task."  Importance="high" />
      <Exec Command="stuff" />
  </Target>
  <Target Name="AfterBuild" DependsOnTargets="AfterBuild1;AfterBuild2" />

If you need to constrain their order, just make AfterBuild2 depend on AfterBuild1 with DependsOnTargets="AfterBuild1".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文