我试图两次调用几个项目的MSbuild。第一次没有任何干净,但如果失败,我将调用一个干净,然后是一个新的构建。 (原因是我希望我的构建速度很快,但如果失败则恢复干净,恢复nuget包构建等)。这可以工作,但如果第一次调用失败,它的构建仍然会失败(它将continueonerror设置为true,所以我不希望它失败......)。以下是构建文件的相关部分:
<ItemGroup>
<ProjectsToPublish Include="X.sln" />
</ItemGroup>
<Target Name="RestoreAllPackages">
<Message Text="@(ProjectsToPublish)" />
<Exec Command='"$(MSBuildProjectDirectory)\.nuget\nuget.exe" restore "$(MSBuildProjectDirectory)\%(ProjectsToPublish.Identity)"'
/>
</Target>
<Target Name="Build" >
<MSBuild Projects="@(ProjectsToPublish)" Properties="SkipRestore=True;RunCodeAnalysis=False;Retries=10;RetryDelayMilliseconds=50"
BuildInParallel="true" ContinueOnError="WarnAndContinue" />
<!-- MSBuildLastTaskResult outcome of previous task-->
<PropertyGroup>
<FastBuildFailed>false</FastBuildFailed>
<FastBuildFailed Condition="'$(MSBuildLastTaskResult)' == 'false'" >true</FastBuildFailed>
</PropertyGroup>
<Message Importance="high" Text="Initial build failed? $(FastBuildFailed)" />
<Message Importance="high" Text="Initial build failed will retry" Condition="'$(FastBuildFailed)'" />
<CallTarget Targets="FullBuild" Condition="'$(FastBuildFailed)'" />
</Target>
<Target Name="FullBuild" DependsOnTargets="RestoreAllPackages">
<!--Fake property below to reexecute build exact same properties prevents the build lform re-->
<MSBuild Projects="@(ProjectsToPublish)" Properties="SkipRestore=True;RunCodeAnalysis=False;FakeProperty=one" BuildInParallel="true" />
</Target>
<Target Name="RestoreAllPackages">
<Message Text="@(ProjectsToPublish)" />
<Exec Command='"$(MSBuildProjectDirectory)\.nuget\nuget.exe" restore "$(MSBuildProjectDirectory)\%(ProjectsToPublish.Identity)"'
/>
</Target>
答案 0 :(得分:1)
对于任何有这种相当奇特的错误的人。似乎在TFS构建服务器内部运行构建时,构建服务器会解析日志输出,即使使用ContinueOnError设置也会使构建失败。我的解决方法最终成为<Exec Command="$(MSBuildBinPath)\msbuild.exe @(ProjectsToPublish) /noconlog " ContinueOnError="true" />
基本上使用Exec生成一个新的MSBuild并确保它没有使用/noconlog
输出任何内容
答案 1 :(得分:0)
您可以指定<OnError...
值'WarnAndContinue'
,然后使用条件检查ContinueOnError
属性,而不是使用$(MSBuildLastTaskResult)
。
通用示例:
<Error ContinueOnError="WarnAndContinue" />
<Message Importance="High" Text ="$(MSBuildLastTaskResult)" />
<!-- (Returns false) -->
(我相信"WarnAndContinue"
和$(MSBuildLastTaskResult)
都是在MSBuild 4.0中引入的;它们应该在您的TFS 2012构建服务器上可用。)