2014-12-05 63 views
1

我試圖執行以下目標,但以circular dependency錯誤結束。我有一個停止條件$(Value) > 0在目標Recursive如何遞歸執行MSBuild目標?

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build"> 
    <Target Name="Recursive" Condition="$(Value) > 0"> 
    <PropertyGroup> 
     <Value>$([MSBuild]::Subtract($(Value), 1))</Value> 
    </PropertyGroup> 
    <MSBuild Projects="$(MSBuildProjectFile)" Targets="Display" /> 
    </Target> 

    <Target Name="Display"> 
    <Message Text="Value: $(Value)" /> 
    <MSBuild Projects="$(MSBuildProjectFile)" Targets="Recursive" /> 
    </Target> 

    <PropertyGroup> 
    <Value>10</Value> 
    </PropertyGroup> 

    <Target Name="Build"> 
    <MSBuild Projects="$(MSBuildProjectFile)" Targets="Display" /> 
    </Target> 
</Project> 

回答

1

你停止條件是好的,但你忘了重新計算Value特性傳遞到下一個遞歸。改變你的Recursive這樣的目標:

<Target Name="Recursive" Condition="$(Value) > 0"> 
    <PropertyGroup> 
    <Value>$([MSBuild]::Subtract($(Value), 1))</Value> 
    </PropertyGroup> 
    <MSBuild Projects="$(MSBuildProjectFile)" Targets="Display" 
      Properties="Value=$(Value)" /> 
</Target> 
+0

哇。非常感謝你。 – 2014-12-05 08:02:30