in src/WebJobs.Script/Description/DotNet/PackageManager.cs [41:117]
public Task<PackageRestoreResult> RestorePackagesAsync()
{
var tcs = new TaskCompletionSource<PackageRestoreResult>();
string projectPath = null;
string nugetHome = null;
string nugetFilePath = null;
string currentLockFileHash = null;
try
{
projectPath = Path.Combine(_functionDirectory, DotNetConstants.ProjectFileName);
nugetHome = GetNugetPackagesPath();
nugetFilePath = ResolveNuGetPath();
currentLockFileHash = GetCurrentLockFileHash(_functionDirectory);
// Copy the file to a temporary location, which is where we'll be performing our restore from:
string tempRestoreLocation = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
string restoreProjectPath = Path.Combine(tempRestoreLocation, Path.GetFileName(projectPath));
Directory.CreateDirectory(tempRestoreLocation);
File.Copy(projectPath, restoreProjectPath);
var startInfo = new ProcessStartInfo
{
FileName = nugetFilePath,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true,
UseShellExecute = false,
ErrorDialog = false,
WorkingDirectory = _functionDirectory,
Arguments = string.Format(CultureInfo.InvariantCulture, "restore \"{0}\" --packages \"{1}\"", restoreProjectPath, nugetHome)
};
startInfo.Environment.Add(EnvironmentSettingNames.DotnetSkipFirstTimeExperience, "true");
startInfo.Environment.Add(EnvironmentSettingNames.DotnetAddGlobalToolsToPath, "false");
startInfo.Environment.Add(EnvironmentSettingNames.DotnetNoLogo, "true");
var process = new Process { StartInfo = startInfo };
process.ErrorDataReceived += ProcessDataReceived;
process.OutputDataReceived += ProcessDataReceived;
process.EnableRaisingEvents = true;
process.Exited += (s, e) =>
{
string lockFileLocation = Path.Combine(tempRestoreLocation, "obj", DotNetConstants.ProjectLockFileName);
if (process.ExitCode == 0 && File.Exists(lockFileLocation))
{
File.Copy(lockFileLocation, Path.Combine(_functionDirectory, DotNetConstants.ProjectLockFileName), true);
}
string newLockFileHash = GetCurrentLockFileHash(_functionDirectory);
var result = new PackageRestoreResult
{
IsInitialInstall = string.IsNullOrEmpty(currentLockFileHash),
ReferencesChanged = !string.Equals(currentLockFileHash, newLockFileHash),
};
tcs.SetResult(result);
process.Close();
};
_logger.PackageManagerStartingPackagesRestore();
process.Start();
process.BeginErrorReadLine();
process.BeginOutputReadLine();
}
catch (Exception exc)
{
_logger.PackageManagerRestoreFailed(exc, _functionDirectory, projectPath, nugetHome, nugetFilePath, currentLockFileHash);
tcs.SetException(exc);
}
return tcs.Task;
}