Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit cfbc76d

Browse files
committed
Tools restore could fail if the binaries/libraries used for tracking Inputs/Outputs were locked. Switch to a semaphore file and allow it to warn in the rare case it fails to touch it successfully.
Merged from CS#1485206. [tfs-changeset: 1493243]
1 parent d72d94a commit cfbc76d

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

dir.targets

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@
5959
</Task>
6060
</UsingTask>
6161

62+
<!--
63+
Use a semaphore file to determine the need to restore build tools to avoid conflicts with locked binaries.
64+
-->
65+
<PropertyGroup>
66+
<BuildToolsSemaphore>$(ToolsDir)BuildTools.semaphore</BuildToolsSemaphore>
67+
</PropertyGroup>
68+
6269
<!--
6370
Needed to avoid the IntialTargets from having an Output which ends up getting
6471
added to the output references when you have a project to project reference.
@@ -67,7 +74,7 @@
6774

6875
<Target Name="_RestoreBuildTools"
6976
Inputs="$(MSBuildThisFileDirectory)dir.props;$(SourceDir).nuget/packages.$(OsEnvironment).config"
70-
Outputs="$(ToolsDir)Microsoft.DotNet.Build.Tasks.dll;$(NugetToolPath);$(DnuToolPath)">
77+
Outputs="$(BuildToolsSemaphore)">
7178
<Message Importance="High" Text="Restoring build tools..." />
7279

7380
<Copy Condition="Exists('$(NuGetCachedPath)')" SourceFiles="$(NuGetCachedPath)" DestinationFiles="$(NuGetToolPath)" SkipUnchangedFiles="true" />
@@ -95,16 +102,17 @@
95102
<Exec Condition="'$(OsEnvironment)'=='Unix'"
96103
Command="find '$(RoslynPackageDir)tools' -name &quot;*.exe&quot; -exec chmod &quot;+x&quot; '{}' ';'" />
97104

98-
<Error Condition="'$(ErrorIfBuildToolsRestoredFromIndividualProject)'=='true'"
99-
Text="The build tools package was just restored and so we cannot continue the build of an individual project because targets from the build tools package were not able to be imported. Please retry the build the individual project again." />
100-
101105
<!--
102-
There are cases where the inputs could be newer than the outputs but the
103-
download or restore may not need to update. In such cases we need to touch
104-
these files otherwise we continually run this target over and over for
105-
every project until these files are cleaned (if the are ever cleaned).
106+
Touch our semaphore file to ensure Inputs/Outputs comparison for this target will show that we're up to date.
107+
Ignore failures in the unlikely, but possible, event that we hit this from two projects simultaneously.
106108
-->
107-
<Touch Files="$(ToolsDir)Microsoft.DotNet.Build.Tasks.dll;$(NugetToolPath);$(DnuToolPath)" />
109+
<Touch Files="$(BuildToolsSemaphore)"
110+
ContinueOnError="WarnAndContinue"
111+
AlwaysCreate="true"
112+
ForceTouch="true" />
113+
114+
<Error Condition="'$(ErrorIfBuildToolsRestoredFromIndividualProject)'=='true'"
115+
Text="The build tools package was just restored and so we cannot continue the build of an individual project because targets from the build tools package were not able to be imported. Please retry the build the individual project again." />
108116
</Target>
109117

110118
<!-- Provide default targets which can be hooked onto or overridden as necessary -->

0 commit comments

Comments
 (0)