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 目标中,它会填充。

我怎样才能传递/引用这个值?

4

2 回答 2

0

我能够弄清楚这一点。

本质上,在 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>
于 2012-02-15T00:15:25.753 回答
0

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

作为一种解决方法,使用普通的 MSBuild 机制设置 MSBuild 中目标的执行顺序,使用属性 DependsOnTargets、BeforeTargets 或 AfterTargets。

于 2012-02-14T05:20:44.080 回答