Test improvements (#17428)
Retry adding package and print reason for failure
This commit is contained in:
parent
b24b92494a
commit
32a2cc5943
|
|
@ -200,12 +200,18 @@ namespace Microsoft.DotNet.OpenApi.Commands
|
||||||
var packageId = kvp.Key;
|
var packageId = kvp.Key;
|
||||||
var version = urlPackages != null && urlPackages.ContainsKey(packageId) ? urlPackages[packageId] : kvp.Value;
|
var version = urlPackages != null && urlPackages.ContainsKey(packageId) ? urlPackages[packageId] : kvp.Value;
|
||||||
|
|
||||||
|
await TryAddPackage(packageId, version, projectFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task TryAddPackage(string packageId, string packageVersion, FileInfo projectFile)
|
||||||
|
{
|
||||||
var args = new[] {
|
var args = new[] {
|
||||||
"add",
|
"add",
|
||||||
"package",
|
"package",
|
||||||
packageId,
|
packageId,
|
||||||
"--version",
|
"--version",
|
||||||
version,
|
packageVersion,
|
||||||
"--no-restore"
|
"--no-restore"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -224,7 +230,7 @@ namespace Microsoft.DotNet.OpenApi.Commands
|
||||||
RedirectStandardOutput = true,
|
RedirectStandardOutput = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
var process = Process.Start(startInfo);
|
using var process = Process.Start(startInfo);
|
||||||
|
|
||||||
var timeout = 20;
|
var timeout = 20;
|
||||||
if (!process.WaitForExit(timeout * 1000))
|
if (!process.WaitForExit(timeout * 1000))
|
||||||
|
|
@ -234,10 +240,12 @@ namespace Microsoft.DotNet.OpenApi.Commands
|
||||||
|
|
||||||
if (process.ExitCode != 0)
|
if (process.ExitCode != 0)
|
||||||
{
|
{
|
||||||
Out.Write(process.StandardOutput.ReadToEnd());
|
var output = await process.StandardOutput.ReadToEndAsync();
|
||||||
Error.Write(process.StandardError.ReadToEnd());
|
var error = await process.StandardError.ReadToEndAsync();
|
||||||
throw new ArgumentException($"Could not add package `{packageId}` to `{projectFile.Directory}`");
|
await Out.WriteAsync(output);
|
||||||
}
|
await Error.WriteAsync(error);
|
||||||
|
|
||||||
|
throw new ArgumentException($"Could not add package `{packageId}` to `{projectFile.Directory}` due to: `{error}`");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue