我尝试执行以下目标但最终出现circular dependency
错误。我在目标$(Value) > 0
中确实有一个停止条件Recursive
:
<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>
答案 0 :(得分: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>