MSBuild 条件执行?

发布于 2024-09-27 15:18:26 字数 647 浏览 1 评论 0原文

我正在使用

例如,

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

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

发布评论

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

评论(4

北斗星光 2024-10-04 15:18:26

您应该能够使用TargetOutputs 参数

<MSBuild Projects="" >
   <Output TaskParameter="TargetOutputs" ItemName="AssembliesBuiltByChildProjects" />
</MSBuild>
<Message Text="Assemblies built: @(AssembliesBuiltByChildProjects)" /> <!-- just for debug -->
<Exec Command="" Condition="'@(AssembliesBuiltByChildProjects)'!=''" />

You should be able to use the TargetOutputs parameter:

<MSBuild Projects="" >
   <Output TaskParameter="TargetOutputs" ItemName="AssembliesBuiltByChildProjects" />
</MSBuild>
<Message Text="Assemblies built: @(AssembliesBuiltByChildProjects)" /> <!-- just for debug -->
<Exec Command="" Condition="'@(AssembliesBuiltByChildProjects)'!=''" />
乖乖兔^ω^ 2024-10-04 15:18:26

如果您可以将以下内容添加到每个项目中:

<Target Name="DoStuffWithNewlyCompiledAssembly">
    <Exec Command="" />
</Target>

...那么您只需要添加一个属性:

<Target Name="Name">
  <MSBuild Projects="" Properties="TargetsTriggeredByCompilation=DoStuffWithNewlyCompiledAssembly" />
</Target>

这之所以有效,是因为 Microsoft 的聪明人在 CoreCompile 目标的末尾添加了以下行: Microsoft.[CSharp|VisualBasic][.Core].targets(文件名取决于语言和 MSBuild/Visual Studio 版本)。

<CallTarget Targets="$(TargetsTriggeredByCompilation)" Condition="'$(TargetsTriggeredByCompilation)' != ''"/>

因此,如果您在 TargetsTriggeredByCompilation 属性中指定目标名称,则在 CoreCompile 运行时您的目标将运行,而在 CoreCompile 运行时您的目标将不会运行被跳过(例如,因为输出程序集相对于代码来说已经是最新的)。

If you can add the following to each of your projects:

<Target Name="DoStuffWithNewlyCompiledAssembly">
    <Exec Command="" />
</Target>

... then you only need to add a property:

<Target Name="Name">
  <MSBuild Projects="" Properties="TargetsTriggeredByCompilation=DoStuffWithNewlyCompiledAssembly" />
</Target>

This works because someone smart at Microsoft added the following line at the end of the CoreCompile target in Microsoft.[CSharp|VisualBasic][.Core].targets (the file name depends on the language and MSBuild/Visual Studio version).

<CallTarget Targets="$(TargetsTriggeredByCompilation)" Condition="'$(TargetsTriggeredByCompilation)' != ''"/>

So if you specify a target name in the TargetsTriggeredByCompilation property, your target will run if CoreCompile runs-- and your target will not run if CoreCompile is skipped (e.g. because the output assembly is already up-to-date with respect to the code).

清音悠歌 2024-10-04 15:18:26

你问错了问题。

Exec 没有任何条件,但是您可以在 Target 元素上有条件,可以像这样使用。

<Target Name="Name" Condition="@(AssembliesBuiltByChildProjects)'!=''">
    <MSBuild Projects="">
        <Output TaskParameter="TargetOutputs" ItemName="AssembliesBuiltByChildProjects" />
    </MSBuild>
    <Exec Command=""/>
  </Target>

<Target Name="Name" Condition="@(AssembliesBuiltByChildProjects)'==''">
    ...
</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.

<Target Name="Name" Condition="@(AssembliesBuiltByChildProjects)'!=''">
    <MSBuild Projects="">
        <Output TaskParameter="TargetOutputs" ItemName="AssembliesBuiltByChildProjects" />
    </MSBuild>
    <Exec Command=""/>
  </Target>

<Target Name="Name" Condition="@(AssembliesBuiltByChildProjects)'==''">
    ...
</Target>
终遇你 2024-10-04 15:18:26

我确实找到了一个满足我需求的解决方案,尽管它可能不是最佳解决方案。

请在此处查看我对其他问题的回答: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

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