Merge pull request #1175 from dotnet/pakrym/1096

Fix NRE in restore
This commit is contained in:
Piotr Puszkiewicz 2016-02-01 20:11:32 -08:00
commit 44ac20a4ce

View file

@ -131,11 +131,12 @@ namespace Microsoft.DotNet.Tools.Restore
{ {
var tempPath = Path.Combine(tempRoot, Guid.NewGuid().ToString(), "bin"); var tempPath = Path.Combine(tempRoot, Guid.NewGuid().ToString(), "bin");
RestoreToolToPath(tooldep, restoreTask.Arguments, tempPath, quiet); var restoreSucceded = RestoreToolToPath(tooldep, restoreTask.Arguments, tempPath, quiet);
if (restoreSucceded)
CreateDepsInPackageCache(tooldep, tempPath); {
CreateDepsInPackageCache(tooldep, tempPath);
PersistLockFile(tooldep, tempPath, restoreTask.ProjectDirectory); PersistLockFile(tooldep, tempPath, restoreTask.ProjectDirectory);
}
} }
finally finally
{ {
@ -182,7 +183,7 @@ namespace Microsoft.DotNet.Tools.Restore
File.Move(Path.Combine(calculator.GetOutputDirectoryPath(Constants.DefaultConfiguration), "bin" + FileNameSuffixes.Deps), depsPath); File.Move(Path.Combine(calculator.GetOutputDirectoryPath(Constants.DefaultConfiguration), "bin" + FileNameSuffixes.Deps), depsPath);
} }
private static void RestoreToolToPath(LibraryRange tooldep, IEnumerable<string> args, string tempPath, bool quiet) private static bool RestoreToolToPath(LibraryRange tooldep, IEnumerable<string> args, string tempPath, bool quiet)
{ {
Directory.CreateDirectory(tempPath); Directory.CreateDirectory(tempPath);
var projectPath = Path.Combine(tempPath, Project.FileName); var projectPath = Path.Combine(tempPath, Project.FileName);
@ -190,7 +191,7 @@ namespace Microsoft.DotNet.Tools.Restore
Console.WriteLine($"Restoring Tool '{tooldep.Name}' for '{projectPath}' in '{tempPath}'"); Console.WriteLine($"Restoring Tool '{tooldep.Name}' for '{projectPath}' in '{tempPath}'");
File.WriteAllText(projectPath, GenerateProjectJsonContents(new[] {"dnxcore50"}, tooldep)); File.WriteAllText(projectPath, GenerateProjectJsonContents(new[] {"dnxcore50"}, tooldep));
NuGet3.Restore(new [] { $"{projectPath}", "--runtime", $"{DefaultRid}"}.Concat(args), quiet); return NuGet3.Restore(new [] { $"{projectPath}", "--runtime", $"{DefaultRid}"}.Concat(args), quiet) == 0;
} }
private static string GenerateProjectJsonContents(IEnumerable<string> frameworks, LibraryRange tooldep) private static string GenerateProjectJsonContents(IEnumerable<string> frameworks, LibraryRange tooldep)