MSBuild - 目标依赖关系图中的循环依赖关系

时间:2015-12-21 14:46:38

标签: tfs msbuild tfs2013

我的构建中出现以下错误

错误MSB4006:目标依赖关系图中存在循环依赖关系,涉及目标“DoPublish”。

DoPublish正在触发Publish,我假设Build。我怎么能避免这种情况。

我正在使用Visual Studio构建。我正在使用MSBUILD和目标/ t:UpdateVersion; DoPublish;发布,这是有效的。我想在TFS中使用Visual Studio构建而不是MSBUILD

项目:

<Target Name="UpdateVersion"  AfterTargets="PostBuildEvent">
    <RevisionTask>
      <Output TaskParameter="PublishVersion" PropertyName="PublishVersion" />
    </RevisionTask>
    <Message Text="The Version is $(PublishVersion)" Importance="high" />
    <PropertyGroup>
      <ApplicationVersion>$(PublishVersion)</ApplicationVersion>
    </PropertyGroup>
    <ItemGroup>
      <ConfigFile Include="$(MSBuildProjectDirectory)\Configs\$(Configuration)\AppDeploy.config" />
    </ItemGroup>
    <Copy SourceFiles="@(ConfigFile)" DestinationFolder="$(TargetDir)" Condition=" '$(Configuration)' == 'DEV' OR '$(Configuration)' == 'SIT' OR '$(Configuration)' == 'UAT' " ContinueOnError="true" />
    <Copy SourceFiles="@(ConfigFile)" DestinationFolder="$(MSBuildProjectDirectory)" Condition=" '$(Configuration)' == 'DEV' OR '$(Configuration)' == 'SIT' OR '$(Configuration)' == 'UAT' " ContinueOnError="true" />
    <Message Text="Copying File from $(MSBuildProjectDirectory)\Configs\$(Configuration)\Web.config to $(TargetDir)" Importance="high" />
  </Target>
<Target Name="DoPublish" AfterTargets="UpdateVersion"  Condition=" '$(BuildingInsideVisualStudio)' != '' ">
    <MSBuild Projects="$(ProjectFileName)"    Targets="Publish"    Properties="ApplicationVersion=$(PublishVersion)" />
    <!-- Write publish.htm file for ClickOnce -->
    <Message Text="FileUpdate - $(ProjectDir)\Configs\publish.htm:  Replace {PublishVersion} with $(PublishVersion)" Importance="high" />
    <FileUpdate Files="$(ProjectDir)\Configs\publish.htm" IgnoreCase="true" Multiline="true" Singleline="false" Regex="{PublishVersion}" ReplacementText="$(PublishVersion)" />
    <Message Text="FileUpdate - $(ProjectDir)\Configs\publish.htm:  Replace {AssemblyName} with $(AssemblyName)" Importance="high" />
    <FileUpdate Files="$(ProjectDir)\Configs\publish.htm" IgnoreCase="true" Multiline="true" Singleline="false" Regex="{AssemblyName}" ReplacementText="$(AssemblyName)" />
    <Message Text="FileUpdate - $(ProjectDir)\Configs\publish.htm:  Replace {ProductName} with $(ProductName)" Importance="high" />
    <FileUpdate Files="$(ProjectDir)\Configs\publish.htm" IgnoreCase="true" Multiline="true" Singleline="false" Regex="{ProductName}" ReplacementText="$(ProductName)" />
    <Copy SourceFiles="$(ProjectDir)\Configs\publish.htm" DestinationFiles="$(PublishDir)publish.htm" />
  </Target>

2 个答案:

答案 0 :(得分:1)

我创建了一个Web应用程序项目,并在我的环境(TFS2015)上对此进行了测试,并保留了以下代码:

<Target Name="UpdateVersion" AfterTargets="PostBuildEvent">
    <Message Text="The Version is $(PublishVersion)" Importance="high" />
    <PropertyGroup>
      <ApplicationVersion>$(PublishVersion)</ApplicationVersion>
    </PropertyGroup>
    <Message Text="Copying File from $(MSBuildProjectDirectory)\Configs\$(Configuration)\Web.config to $(TargetDir)" Importance="high" />
  </Target>
  <Target Name="DoPublish" AfterTargets="UpdateVersion" Condition="'$(BuildingInsideVisualStudio)' != 'true'">
    <MSBuild Projects="$(ProjectFileName)" Targets="Publish" />
  </Target>

但我无法重现这个问题。构建可以成功完成。在“DoPublish”目标中未添加“Target =”Publish“时,我只能看到MSB4006错误。

我将条件=“''$(BuildingInsideVisualStudio)'!=''”更改为条件=“''$(BuildingInsideVisualStudio)'!='true'” as在我的环境下,BuildingInsideVisualStudio值始终为空。 “DoPublish”目标不能运行Condition =“'$(BuildingInsideVisualStudio)'!=''”。

由于我无法添加评论,我有一个问题需要在这里查看:在TFS中使用Visual Studio构建而不是MSBUILD是什么意思?

答案 1 :(得分:1)

看到这个post后,我提出了覆盖AfterPubish目标的类似解决方案。

要更正循环依赖关系,只需将目标名称更改为AfterPublish并删除AfterTargerts属性。

<Target Name="AfterPublish"  Condition=" '$(BuildingInsideVisualStudio)' != '' ">
    <MSBuild Projects="$(ProjectFileName)"    Targets="Publish"    Properties="ApplicationVersion=$(PublishVersion)" />
    <!-- Write publish.htm file for ClickOnce -->
    <Message Text="FileUpdate - $(ProjectDir)\Configs\publish.htm:  Replace {PublishVersion} with $(PublishVersion)" Importance="high" />
    <FileUpdate Files="$(ProjectDir)\Configs\publish.htm" IgnoreCase="true" Multiline="true" Singleline="false" Regex="{PublishVersion}" ReplacementText="$(PublishVersion)" />
    <Message Text="FileUpdate - $(ProjectDir)\Configs\publish.htm:  Replace {AssemblyName} with $(AssemblyName)" Importance="high" />
    <FileUpdate Files="$(ProjectDir)\Configs\publish.htm" IgnoreCase="true" Multiline="true" Singleline="false" Regex="{AssemblyName}" ReplacementText="$(AssemblyName)" />
    <Message Text="FileUpdate - $(ProjectDir)\Configs\publish.htm:  Replace {ProductName} with $(ProductName)" Importance="high" />
    <FileUpdate Files="$(ProjectDir)\Configs\publish.htm" IgnoreCase="true" Multiline="true" Singleline="false" Regex="{ProductName}" ReplacementText="$(ProductName)" />
    <Copy SourceFiles="$(ProjectDir)\Configs\publish.htm" DestinationFiles="$(PublishDir)publish.htm" />
  </Target>