使用 MSBuild 将输出项传递到单独的目标

发布于 2025-01-05 15:52:19 字数 1016 浏览 0 评论 0原文

我正在创建一个构建脚本,在其中输出 MSBuild 的 TargetOutputs,然后想要在单独的目标中调用 FXCop,并在 TargetAssemblies 中使用这些输出。

<Target Name="Build">
    <MSBuild Projects="@(Projects)"
             Properties="Platform=$(Platform);Configuration=$(Configuration);"
             Targets="Build"
             ContinueOnError="false">
      <Output TaskParameter="TargetOutputs" ItemName="TargetDLLs"/>
    </MSBuild>
    <CallTarget Targets="FxCopReport" />
</Target>

<Target Name="FxCopyReport">
    <Message Text="FXCop assemblies to test: @(TargetDLLs)" />
    <FxCop
      ToolPath="$(FXCopToolPath)"
      RuleLibraries="@(FxCopRuleAssemblies)"
      AnalysisReportFileName="FXCopReport.html"
      TargetAssemblies="@(TargetDLLs)"
      OutputXslFileName="$(FXCopToolPath)\Xml\FxCopReport.xsl"
      ApplyOutXsl="True"
      FailOnError="False" />
</Target>

当我在 FxCopyReport 目标中运行此命令时,TargetDLLs 的消息为空,而如果我将其放入 Build 目标中,它会填充。

我如何传递/引用这个值?

I am creating a buildscript, where I'm outputting the TargetOutputs of an MSBuild, then wanting to call FXCop in a separate target, and using those outputs in the TargetAssemblies.

<Target Name="Build">
    <MSBuild Projects="@(Projects)"
             Properties="Platform=$(Platform);Configuration=$(Configuration);"
             Targets="Build"
             ContinueOnError="false">
      <Output TaskParameter="TargetOutputs" ItemName="TargetDLLs"/>
    </MSBuild>
    <CallTarget Targets="FxCopReport" />
</Target>

<Target Name="FxCopyReport">
    <Message Text="FXCop assemblies to test: @(TargetDLLs)" />
    <FxCop
      ToolPath="$(FXCopToolPath)"
      RuleLibraries="@(FxCopRuleAssemblies)"
      AnalysisReportFileName="FXCopReport.html"
      TargetAssemblies="@(TargetDLLs)"
      OutputXslFileName="$(FXCopToolPath)\Xml\FxCopReport.xsl"
      ApplyOutXsl="True"
      FailOnError="False" />
</Target>

When I run this, in the FxCopyReport target, the Message of TargetDLLs in empty, whereas if I put this in the Build target, it populates.

How can I pass/reference this value?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

濫情▎り 2025-01-12 15:52:20

我能够弄清楚这一点。

本质上,在 MSBuild 步骤之后,我创建了一个 ItemGroup,然后在调用 Target 中引用它。

<Target Name="Build">
    <Message Text="Building Solution Projects: %(Projects.FullPath)" />
    <MSBuild Projects="@(Projects)"
             Properties="Platform=$(Platform);Configuration=$(Configuration);"
             Targets="Build"
             ContinueOnError="false">
      <Output TaskParameter="TargetOutputs" ItemName="TargetDllOutputs"/>
    </MSBuild>
    <ItemGroup>
      <TestAssemblies Include="@(TargetDllOutputs)" />
    </ItemGroup>
  </Target>

  <Target Name="FXCopReport">
    <Message Text="FXCop assemblies to test: @(TestAssemblies)" />
    <FxCop
      ToolPath="$(FXCopToolPath)"
      RuleLibraries="@(FxCopRuleAssemblies)"
      AnalysisReportFileName="$(BuildPath)\$(FxCopReportFile)"
      TargetAssemblies="@(TestAssemblies)"
      OutputXslFileName="$(FXCopToolPath)\Xml\FxCopReport.xsl"
      Rules="$(FxCopExcludeRules)"
      ApplyOutXsl="True"
      FailOnError="True" />
    <Message Text="##teamcity[importData id='FxCop' file='$(BuildPath)\$(FxCopReportFile)']" Condition="'$(TEAMCITY_BUILD_PROPERTIES_FILE)' != ''" />
  </Target>

I was able to figure this one out.

Essentially, after the MSBuild step, I created an ItemGroup, which I then referenced in the calling Target.

<Target Name="Build">
    <Message Text="Building Solution Projects: %(Projects.FullPath)" />
    <MSBuild Projects="@(Projects)"
             Properties="Platform=$(Platform);Configuration=$(Configuration);"
             Targets="Build"
             ContinueOnError="false">
      <Output TaskParameter="TargetOutputs" ItemName="TargetDllOutputs"/>
    </MSBuild>
    <ItemGroup>
      <TestAssemblies Include="@(TargetDllOutputs)" />
    </ItemGroup>
  </Target>

  <Target Name="FXCopReport">
    <Message Text="FXCop assemblies to test: @(TestAssemblies)" />
    <FxCop
      ToolPath="$(FXCopToolPath)"
      RuleLibraries="@(FxCopRuleAssemblies)"
      AnalysisReportFileName="$(BuildPath)\$(FxCopReportFile)"
      TargetAssemblies="@(TestAssemblies)"
      OutputXslFileName="$(FXCopToolPath)\Xml\FxCopReport.xsl"
      Rules="$(FxCopExcludeRules)"
      ApplyOutXsl="True"
      FailOnError="True" />
    <Message Text="##teamcity[importData id='FxCop' file='$(BuildPath)\$(FxCopReportFile)']" Condition="'$(TEAMCITY_BUILD_PROPERTIES_FILE)' != ''" />
  </Target>
水晶透心 2025-01-12 15:52:19

Sayed Ibrahim Hashimi(《Inside MSBuild》一书的合著者)有一篇 博客文章 ),描述了您在 2005 年遇到的问题。本质上 CallTarget 任务的行为很奇怪。我不确定这是一个错误还是设计行为,但 MSBuild 4.0 中的行为仍然相同。

作为解决方法,请使用正常的 MSBuild 机制在 MSBuild 中设置目标的执行顺序,使用属性 DependsOnTargets、BeforeTargets 或 AfterTargets。

There is a blog post by Sayed Ibrahim Hashimi (co-author of Inside MSBuild book), describing the issue you ran into, dating back in 2005. Essentially CallTarget task is behaving weird. I'm not sure if it is a bug or designed behavior, but the behavior is still the same in MSBuild 4.0.

As a workaround, use normal MSBuild mechanism of setting order of execution of targets in MSBuild, using attributes DependsOnTargets, BeforeTargets or AfterTargets.

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