forked from dotnet/buildtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent concurrent restore of same project.json
DNX has an issue with concurrent restore: aspnet/dnx#1682 Previously I would workaround by copying to intermediate, but this breaks in official build where intermediate is not under the scope of our nuget.config, so custom package sources are ignored. Fix this instead by wrapping the call to dnu restore with a mutex unique to the project.json name. We only need to do this for the test project.json because that is the only one we'll restore concurrently.
- Loading branch information
Showing
3 changed files
with
49 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using Microsoft.Build.Framework; | ||
using Microsoft.Build.Tasks; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.DotNet.Build.Tasks | ||
{ | ||
public class ExecWithMutex : Exec | ||
{ | ||
[Required] | ||
public string MutexName | ||
{ | ||
get; | ||
set; | ||
} | ||
|
||
protected override int ExecuteTool(string pathToTool, string responseFileCommands, string commandLineCommands) | ||
{ | ||
string actualMutexName = MutexName.Replace(Path.DirectorySeparatorChar, '_'); | ||
bool created = false; | ||
|
||
using (Mutex mutex = new Mutex(true, actualMutexName, out created)) | ||
{ | ||
try | ||
{ | ||
if (!created) | ||
{ | ||
mutex.WaitOne(); | ||
} | ||
return base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands); | ||
} | ||
finally | ||
{ | ||
mutex.ReleaseMutex(); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters