@@ -28,7 +28,7 @@ namespace Wasm.Build.Tests
2828 public abstract class BuildTestBase : IClassFixture < SharedBuildPerTestClassFixture > , IDisposable
2929 {
3030 public const string DefaultTargetFramework = "net7.0" ;
31- public static readonly string NuGetConfigFileNameForDefaultFramework = $ "nuget7.config ";
31+ public const string DefaultTargetFrameworkForBlazor = "net7.0 ";
3232 protected static readonly bool s_skipProjectCleanup ;
3333 protected static readonly string s_xharnessRunnerCommand ;
3434 protected string ? _projectDir ;
@@ -49,6 +49,9 @@ public abstract class BuildTestBase : IClassFixture<SharedBuildPerTestClassFixtu
4949
5050 public static bool IsUsingWorkloads => s_buildEnv . IsWorkload ;
5151 public static bool IsNotUsingWorkloads => ! s_buildEnv . IsWorkload ;
52+ public static string GetNuGetConfigPathFor ( string targetFramework ) =>
53+ Path . Combine ( BuildEnvironment . TestDataPath , "nuget8.config" ) ; // for now - we are still using net7, but with
54+ // targetFramework == "net7.0" ? "nuget7.config" : "nuget8.config");
5255
5356 static BuildTestBase ( )
5457 {
@@ -289,7 +292,7 @@ protected void InitPaths(string id)
289292 Directory . CreateDirectory ( _logPath ) ;
290293 }
291294
292- protected static void InitProjectDir ( string dir , bool addNuGetSourceForLocalPackages = false )
295+ protected void InitProjectDir ( string dir , bool addNuGetSourceForLocalPackages = false , string targetFramework = DefaultTargetFramework )
293296 {
294297 Directory . CreateDirectory ( dir ) ;
295298 File . WriteAllText ( Path . Combine ( dir , "Directory.Build.props" ) , s_buildEnv . DirectoryBuildPropsContents ) ;
@@ -300,15 +303,13 @@ protected static void InitProjectDir(string dir, bool addNuGetSourceForLocalPack
300303 {
301304 File . WriteAllText ( targetNuGetConfigPath ,
302305 GetNuGetConfigWithLocalPackagesPath (
303- Path . Combine ( BuildEnvironment . TestDataPath , NuGetConfigFileNameForDefaultFramework ) ,
306+ GetNuGetConfigPathFor ( targetFramework ) ,
304307 s_buildEnv . BuiltNuGetsPath ) ) ;
305308 }
306309 else
307310 {
308- File . Copy ( Path . Combine ( BuildEnvironment . TestDataPath , NuGetConfigFileNameForDefaultFramework ) ,
309- targetNuGetConfigPath ) ;
311+ File . Copy ( GetNuGetConfigPathFor ( targetFramework ) , targetNuGetConfigPath ) ;
310312 }
311- Directory . CreateDirectory ( Path . Combine ( dir , ".nuget" ) ) ;
312313 }
313314
314315 protected const string SimpleProjectTemplate =
@@ -414,7 +415,14 @@ protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProp
414415 AssertRuntimePackPath ( result . buildOutput , options . TargetFramework ?? DefaultTargetFramework ) ;
415416
416417 string bundleDir = Path . Combine ( GetBinDir ( config : buildArgs . Config , targetFramework : options . TargetFramework ?? DefaultTargetFramework ) , "AppBundle" ) ;
417- AssertBasicAppBundle ( bundleDir , buildArgs . ProjectName , buildArgs . Config , options . MainJS ?? "test-main.js" , options . HasV8Script , options . HasIcudt , options . DotnetWasmFromRuntimePack ?? ! buildArgs . AOT , options . TargetFramework ?? DefaultTargetFramework ) ;
418+ AssertBasicAppBundle ( bundleDir ,
419+ buildArgs . ProjectName ,
420+ buildArgs . Config ,
421+ options . MainJS ?? "test-main.js" ,
422+ options . HasV8Script ,
423+ options . TargetFramework ?? DefaultTargetFramework ,
424+ options . HasIcudt ,
425+ options . DotnetWasmFromRuntimePack ?? ! buildArgs . AOT ) ;
418426 }
419427
420428 if ( options . UseCache )
@@ -430,17 +438,16 @@ protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProp
430438 }
431439 }
432440
433- public void InitBlazorWasmProjectDir ( string id )
441+ public void InitBlazorWasmProjectDir ( string id , string targetFramework = DefaultTargetFrameworkForBlazor )
434442 {
435443 InitPaths ( id ) ;
436444 if ( Directory . Exists ( _projectDir ) )
437445 Directory . Delete ( _projectDir , recursive : true ) ;
438446 Directory . CreateDirectory ( _projectDir ) ;
439- Directory . CreateDirectory ( Path . Combine ( _projectDir , ".nuget" ) ) ;
440447
441448 File . WriteAllText ( Path . Combine ( _projectDir , "nuget.config" ) ,
442449 GetNuGetConfigWithLocalPackagesPath (
443- Path . Combine ( BuildEnvironment . TestDataPath , NuGetConfigFileNameForDefaultFramework ) ,
450+ GetNuGetConfigPathFor ( targetFramework ) ,
444451 s_buildEnv . BuiltNuGetsPath ) ) ;
445452
446453 File . Copy ( Path . Combine ( BuildEnvironment . TestDataPath , "Blazor.Directory.Build.props" ) , Path . Combine ( _projectDir , "Directory.Build.props" ) ) ;
@@ -497,8 +504,12 @@ public string CreateBlazorWasmTemplateProject(string id)
497504 protected ( CommandResult , string ) BlazorBuild ( BlazorBuildOptions options , params string [ ] extraArgs )
498505 {
499506 var res = BuildInternal ( options . Id , options . Config , publish : false , setWasmDevel : false , extraArgs ) ;
507+ _testOutput . WriteLine ( $ "BlazorBuild, options.tfm: { options . TargetFramework } ") ;
500508 AssertDotNetNativeFiles ( options . ExpectedFileType , options . Config , forPublish : false , targetFramework : options . TargetFramework ) ;
501- AssertBlazorBundle ( options . Config , isPublish : false , dotnetWasmFromRuntimePack : options . ExpectedFileType == NativeFilesType . FromRuntimePack ) ;
509+ AssertBlazorBundle ( options . Config ,
510+ isPublish : false ,
511+ dotnetWasmFromRuntimePack : options . ExpectedFileType == NativeFilesType . FromRuntimePack ,
512+ targetFramework : options . TargetFramework ) ;
502513
503514 return res ;
504515 }
@@ -507,7 +518,10 @@ public string CreateBlazorWasmTemplateProject(string id)
507518 {
508519 var res = BuildInternal ( options . Id , options . Config , publish : true , setWasmDevel : false , extraArgs ) ;
509520 AssertDotNetNativeFiles ( options . ExpectedFileType , options . Config , forPublish : true , targetFramework : options . TargetFramework ) ;
510- AssertBlazorBundle ( options . Config , isPublish : true , dotnetWasmFromRuntimePack : options . ExpectedFileType == NativeFilesType . FromRuntimePack ) ;
521+ AssertBlazorBundle ( options . Config ,
522+ isPublish : true ,
523+ dotnetWasmFromRuntimePack : options . ExpectedFileType == NativeFilesType . FromRuntimePack ,
524+ targetFramework : options . TargetFramework ) ;
511525
512526 if ( options . ExpectedFileType == NativeFilesType . AOT )
513527 {
@@ -539,17 +553,18 @@ public string CreateBlazorWasmTemplateProject(string id)
539553
540554 CommandResult res = new DotNetCommand ( s_buildEnv , _testOutput )
541555 . WithWorkingDirectory ( _projectDir ! )
556+ . WithEnvironmentVariable ( "NUGET_PACKAGES" , _nugetPackagesDir )
542557 . ExecuteWithCapturedOutput ( combinedArgs )
543558 . EnsureSuccessful ( ) ;
544559
545560 return ( res , logPath ) ;
546561 }
547562
548- protected void AssertDotNetNativeFiles ( NativeFilesType type , string config , bool forPublish , string targetFramework = DefaultTargetFramework )
563+ protected void AssertDotNetNativeFiles ( NativeFilesType type , string config , bool forPublish , string targetFramework )
549564 {
550565 string label = forPublish ? "publish" : "build" ;
551566 string objBuildDir = Path . Combine ( _projectDir ! , "obj" , config , targetFramework , "wasm" , forPublish ? "for-publish" : "for-build" ) ;
552- string binFrameworkDir = FindBlazorBinFrameworkDir ( config , forPublish ) ;
567+ string binFrameworkDir = FindBlazorBinFrameworkDir ( config , forPublish , framework : targetFramework ) ;
553568
554569 string srcDir = type switch
555570 {
@@ -590,7 +605,14 @@ static void AssertRuntimePackPath(string buildOutput, string targetFramework)
590605 throw new XunitException ( $ "Runtime pack path doesn't match.{ Environment . NewLine } Expected: '{ expectedRuntimePackDir } '{ Environment . NewLine } Actual: '{ actualPath } '") ;
591606 }
592607
593- protected static void AssertBasicAppBundle ( string bundleDir , string projectName , string config , string mainJS , bool hasV8Script , bool hasIcudt = true , bool dotnetWasmFromRuntimePack = true , string targetFramework = DefaultTargetFramework )
608+ protected static void AssertBasicAppBundle ( string bundleDir ,
609+ string projectName ,
610+ string config ,
611+ string mainJS ,
612+ bool hasV8Script ,
613+ string targetFramework ,
614+ bool hasIcudt = true ,
615+ bool dotnetWasmFromRuntimePack = true )
594616 {
595617 AssertFilesExist ( bundleDir , new [ ]
596618 {
@@ -638,7 +660,7 @@ protected static void AssertDotNetWasmJs(string bundleDir, bool fromRuntimePack,
638660 same : fromRuntimePack ) ;
639661 }
640662
641- protected static void AssertDotNetJsSymbols ( string bundleDir , bool fromRuntimePack , string targetFramework = DefaultTargetFramework )
663+ protected static void AssertDotNetJsSymbols ( string bundleDir , bool fromRuntimePack , string targetFramework )
642664 => AssertFile ( Path . Combine ( s_buildEnv . GetRuntimeNativeDir ( targetFramework ) , "dotnet.js.symbols" ) ,
643665 Path . Combine ( bundleDir , "dotnet.js.symbols" ) ,
644666 same : fromRuntimePack ) ;
@@ -690,11 +712,11 @@ protected static void AssertFile(string file0, string file1, string? label=null,
690712 return result ;
691713 }
692714
693- protected void AssertBlazorBundle ( string config , bool isPublish , bool dotnetWasmFromRuntimePack , string ? binFrameworkDir = null , string targetFramework = DefaultTargetFramework )
715+ protected void AssertBlazorBundle ( string config , bool isPublish , bool dotnetWasmFromRuntimePack , string targetFramework = DefaultTargetFrameworkForBlazor , string ? binFrameworkDir = null )
694716 {
695- binFrameworkDir ??= FindBlazorBinFrameworkDir ( config , isPublish ) ;
717+ binFrameworkDir ??= FindBlazorBinFrameworkDir ( config , isPublish , targetFramework ) ;
696718
697- AssertBlazorBootJson ( config , isPublish , binFrameworkDir : binFrameworkDir ) ;
719+ AssertBlazorBootJson ( config , isPublish , targetFramework , binFrameworkDir : binFrameworkDir ) ;
698720 AssertFile ( Path . Combine ( s_buildEnv . GetRuntimeNativeDir ( targetFramework ) , "dotnet.wasm" ) ,
699721 Path . Combine ( binFrameworkDir , "dotnet.wasm" ) ,
700722 "Expected dotnet.wasm to be same as the runtime pack" ,
@@ -709,9 +731,9 @@ protected void AssertBlazorBundle(string config, bool isPublish, bool dotnetWasm
709731 same : dotnetWasmFromRuntimePack ) ;
710732 }
711733
712- protected void AssertBlazorBootJson ( string config , bool isPublish , string ? binFrameworkDir = null )
734+ protected void AssertBlazorBootJson ( string config , bool isPublish , string targetFramework = DefaultTargetFrameworkForBlazor , string ? binFrameworkDir = null )
713735 {
714- binFrameworkDir ??= FindBlazorBinFrameworkDir ( config , isPublish ) ;
736+ binFrameworkDir ??= FindBlazorBinFrameworkDir ( config , isPublish , targetFramework ) ;
715737
716738 string bootJsonPath = Path . Combine ( binFrameworkDir , "blazor.boot.json" ) ;
717739 Assert . True ( File . Exists ( bootJsonPath ) , $ "Expected to find { bootJsonPath } ") ;
@@ -728,7 +750,7 @@ protected void AssertBlazorBootJson(string config, bool isPublish, string? binFr
728750 $ "{ msgPrefix } Could not find dotnet.*js in { bootJson } ") ;
729751 }
730752
731- protected string FindBlazorBinFrameworkDir ( string config , bool forPublish , string framework = DefaultTargetFramework )
753+ protected string FindBlazorBinFrameworkDir ( string config , bool forPublish , string framework = DefaultTargetFrameworkForBlazor )
732754 {
733755 string basePath = Path . Combine ( _projectDir ! , "bin" , config , framework ) ;
734756 if ( forPublish )
@@ -1005,6 +1027,6 @@ public record BlazorBuildOptions
10051027 string Id ,
10061028 string Config ,
10071029 NativeFilesType ExpectedFileType ,
1008- string TargetFramework = BuildTestBase . DefaultTargetFramework
1030+ string TargetFramework = BuildTestBase . DefaultTargetFrameworkForBlazor
10091031 ) ;
10101032}
0 commit comments