@@ -36,6 +36,7 @@ public abstract class BuildTestBase : IClassFixture<SharedBuildPerTestClassFixtu
3636 protected string _logPath ;
3737 protected bool _enablePerTestCleanup = false ;
3838 protected SharedBuildPerTestClassFixture _buildContext ;
39+ protected string _nugetPackagesDir = string . Empty ;
3940
4041 // FIXME: use an envvar to override this
4142 protected static int s_defaultPerTestTimeoutMs = RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ? 30 * 60 * 1000 : 15 * 60 * 1000 ;
@@ -63,13 +64,6 @@ static BuildTestBase()
6364 else
6465 s_xharnessRunnerCommand = EnvironmentVariables . XHarnessCliPath ;
6566
66- string ? nugetPackagesPath = Environment . GetEnvironmentVariable ( "NUGET_PACKAGES" ) ;
67- if ( ! string . IsNullOrEmpty ( nugetPackagesPath ) )
68- {
69- if ( ! Directory . Exists ( nugetPackagesPath ) )
70- Directory . CreateDirectory ( nugetPackagesPath ) ;
71- }
72-
7367 Console . WriteLine ( "" ) ;
7468 Console . WriteLine ( $ "==============================================================================================") ;
7569 Console . WriteLine ( $ "=============== Running with { ( s_buildEnv . IsWorkload ? "Workloads" : "No workloads" ) } ===============") ;
@@ -286,7 +280,12 @@ protected void InitPaths(string id)
286280 if ( _projectDir == null )
287281 _projectDir = Path . Combine ( AppContext . BaseDirectory , id ) ;
288282 _logPath = Path . Combine ( s_buildEnv . LogRootPath , id ) ;
283+ _nugetPackagesDir = Path . Combine ( BuildEnvironment . TmpPath , "nuget" , id ) ;
284+
285+ if ( Directory . Exists ( _nugetPackagesDir ) )
286+ Directory . Delete ( _nugetPackagesDir , recursive : true ) ;
289287
288+ Directory . CreateDirectory ( _nugetPackagesDir ! ) ;
290289 Directory . CreateDirectory ( _logPath ) ;
291290 }
292291
@@ -405,6 +404,7 @@ protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProp
405404 foreach ( var kvp in options . ExtraBuildEnvironmentVariables ! )
406405 envVars [ kvp . Key ] = kvp . Value ;
407406 }
407+ envVars [ "NUGET_PACKAGES" ] = _nugetPackagesDir ;
408408 result = AssertBuild ( sb . ToString ( ) , id , expectSuccess : options . ExpectSuccess , envVars : envVars ) ;
409409
410410 // check that we are using the correct runtime pack!
@@ -487,6 +487,7 @@ public string CreateBlazorWasmTemplateProject(string id)
487487 InitBlazorWasmProjectDir ( id ) ;
488488 new DotNetCommand ( s_buildEnv , _testOutput , useDefaultArgs : false )
489489 . WithWorkingDirectory ( _projectDir ! )
490+ . WithEnvironmentVariable ( "NUGET_PACKAGES" , _nugetPackagesDir )
490491 . ExecuteWithCapturedOutput ( "new blazorwasm" )
491492 . EnsureSuccessful ( ) ;
492493
0 commit comments