private DirectoryPath InstallPackage(PackageDefinition package, DirectoryPath root)
{
var packagePath = root.Combine("libs");
if (!_fileSystem.Exist(packagePath))
{
_fileSystem.GetDirectory(packagePath).Create();
}
var toolsPath = root.Combine("tools");
var nugetToolPath = toolsPath.CombineWithFilePath("nuget.exe");
if (!_fileSystem.Exist(toolsPath))
{
_fileSystem.GetDirectory(toolsPath).Create();
}
if (!_fileSystem.Exist(nugetToolPath))
{
DownloadNuget(nugetToolPath);
}
if (_fileSystem.Exist(packagePath.Combine(package.PackageName)))
{
return packagePath.Combine(package.PackageName);
}
var arguments = $"install \"{package.PackageName}\" -Source \"https://api.nuget.org/v3/index.json\" -PreRelease -ExcludeVersion -OutputDirectory \"{packagePath.FullPath}\"{(!string.IsNullOrWhiteSpace(package.Version) ? $" -Version \"{package.Version}\"" : string.Empty)}";
var fallbackarguments = $"install \"{package.PackageName}\" -Source \"https://api.nuget.org/v3/index.json\" -Source \"https://www.myget.org/F/xunit/api/v3/index.json\" -Source \"https://dotnet.myget.org/F/dotnet-core/api/v3/index.json\" -Source \"https://dotnet.myget.org/F/cli-deps/api/v3/index.json\" -PreRelease -ExcludeVersion -OutputDirectory \"{packagePath.FullPath}\"{(!string.IsNullOrWhiteSpace(package.Version) ? $" -Version \"{package.Version}\"" : string.Empty)}";
ExecuteNuget(nugetToolPath, arguments, fallbackarguments, 3);
// Return the installation directory.
return packagePath.Combine(package.PackageName);
}