【问题标题】:Pass Output items to separate target with MSBuild使用 MSBuild 将输出项传递给单独的目标
【发布时间】:2023-09-20 09:29:01
【问题描述】:

我正在创建一个构建脚本,在其中输出 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 目标中,它会填充。

如何传递/引用这个值?

【问题讨论】:

    标签: msbuild fxcop msbuild-4.0 msbuildcommunitytasks


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      我能够弄清楚这一点。

      基本上,在 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>
      

      【讨论】:

        最近更新 更多