@@ -24,17 +24,6 @@ public NuGetExeRestoreCommand(ITestOutputHelper log, string projectRootPath, str
24
24
25
25
protected override SdkCommandSpec CreateCommand ( IEnumerable < string > args )
26
26
{
27
- var newArgs = new List < string > ( ) ;
28
-
29
- newArgs . Add ( "restore" ) ;
30
-
31
- newArgs . Add ( FullPathProjectFile ) ;
32
-
33
- newArgs . Add ( "-PackagesDirectory" ) ;
34
- newArgs . Add ( PackagesDirectory ?? TestContext . Current . NuGetCachePath ?? string . Empty ) ;
35
-
36
- newArgs . AddRange ( args ) ;
37
-
38
27
if ( string . IsNullOrEmpty ( TestContext . Current . NuGetExePath ) )
39
28
{
40
29
throw new InvalidOperationException ( "Path to nuget.exe not set" ) ;
@@ -58,20 +47,28 @@ protected override SdkCommandSpec CreateCommand(IEnumerable<string> args)
58
47
"https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" :
59
48
$ "https://dist.nuget.org/win-x86-commandline/v{ NuGetExeVersion } /nuget.exe";
60
49
61
- using ( var client = new System . Net . Http . HttpClient ( ) )
62
- using ( var response = client . GetAsync ( url ) . ConfigureAwait ( false ) . GetAwaiter ( ) . GetResult ( ) )
63
- using ( var fs = new FileStream ( nugetExePath , FileMode . CreateNew ) )
50
+ DownloadNuGetAsync ( ) . ConfigureAwait ( false ) . GetAwaiter ( ) . GetResult ( ) ;
51
+
52
+ async Task DownloadNuGetAsync ( )
64
53
{
65
- #pragma warning disable CA2025 // we force synchronous so sourceCacheContext can't be disposed early
66
- response . Content . CopyToAsync ( fs ) . ConfigureAwait ( false ) . GetAwaiter ( ) . GetResult ( ) ;
67
- #pragma warning restore CA2025
54
+ using var client = new System . Net . Http . HttpClient ( ) ;
55
+ using var response = await client . GetAsync ( url ) . ConfigureAwait ( false ) ;
56
+ using var fs = new FileStream ( nugetExePath , FileMode . CreateNew ) ;
57
+ await response . Content . CopyToAsync ( fs ) . ConfigureAwait ( false ) ;
68
58
}
69
59
}
70
60
71
61
var ret = new SdkCommandSpec ( )
72
62
{
73
63
FileName = nugetExePath ,
74
- Arguments = newArgs
64
+ Arguments =
65
+ [
66
+ "restore" ,
67
+ FullPathProjectFile ,
68
+ "-PackagesDirectory" ,
69
+ PackagesDirectory ?? TestContext . Current . NuGetCachePath ?? string . Empty ,
70
+ .. args
71
+ ]
75
72
} ;
76
73
77
74
TestContext . Current . AddTestEnvironmentVariables ( ret . Environment ) ;
0 commit comments