0

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?

mickyjtwin
  • 4,960
  • 13
  • 58
  • 77

2 Answers2

0

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.

seva titov
  • 11,720
  • 2
  • 35
  • 54
0

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>
mickyjtwin
  • 4,960
  • 13
  • 58
  • 77