@@ -28,7 +28,7 @@ namespace Wasm.Build.Tests
28
28
public abstract class BuildTestBase : IClassFixture < SharedBuildPerTestClassFixture > , IDisposable
29
29
{
30
30
public const string DefaultTargetFramework = "net7.0" ;
31
- public static readonly string NuGetConfigFileNameForDefaultFramework = $ "nuget7.config ";
31
+ public const string DefaultTargetFrameworkForBlazor = "net7.0 ";
32
32
protected static readonly bool s_skipProjectCleanup ;
33
33
protected static readonly string s_xharnessRunnerCommand ;
34
34
protected string ? _projectDir ;
@@ -49,6 +49,9 @@ public abstract class BuildTestBase : IClassFixture<SharedBuildPerTestClassFixtu
49
49
50
50
public static bool IsUsingWorkloads => s_buildEnv . IsWorkload ;
51
51
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");
52
55
53
56
static BuildTestBase ( )
54
57
{
@@ -289,7 +292,7 @@ protected void InitPaths(string id)
289
292
Directory . CreateDirectory ( _logPath ) ;
290
293
}
291
294
292
- protected static void InitProjectDir ( string dir , bool addNuGetSourceForLocalPackages = false )
295
+ protected void InitProjectDir ( string dir , bool addNuGetSourceForLocalPackages = false , string targetFramework = DefaultTargetFramework )
293
296
{
294
297
Directory . CreateDirectory ( dir ) ;
295
298
File . WriteAllText ( Path . Combine ( dir , "Directory.Build.props" ) , s_buildEnv . DirectoryBuildPropsContents ) ;
@@ -300,15 +303,13 @@ protected static void InitProjectDir(string dir, bool addNuGetSourceForLocalPack
300
303
{
301
304
File . WriteAllText ( targetNuGetConfigPath ,
302
305
GetNuGetConfigWithLocalPackagesPath (
303
- Path . Combine ( BuildEnvironment . TestDataPath , NuGetConfigFileNameForDefaultFramework ) ,
306
+ GetNuGetConfigPathFor ( targetFramework ) ,
304
307
s_buildEnv . BuiltNuGetsPath ) ) ;
305
308
}
306
309
else
307
310
{
308
- File . Copy ( Path . Combine ( BuildEnvironment . TestDataPath , NuGetConfigFileNameForDefaultFramework ) ,
309
- targetNuGetConfigPath ) ;
311
+ File . Copy ( GetNuGetConfigPathFor ( targetFramework ) , targetNuGetConfigPath ) ;
310
312
}
311
- Directory . CreateDirectory ( Path . Combine ( dir , ".nuget" ) ) ;
312
313
}
313
314
314
315
protected const string SimpleProjectTemplate =
@@ -414,7 +415,14 @@ protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProp
414
415
AssertRuntimePackPath ( result . buildOutput , options . TargetFramework ?? DefaultTargetFramework ) ;
415
416
416
417
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 ) ;
418
426
}
419
427
420
428
if ( options . UseCache )
@@ -430,17 +438,16 @@ protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProp
430
438
}
431
439
}
432
440
433
- public void InitBlazorWasmProjectDir ( string id )
441
+ public void InitBlazorWasmProjectDir ( string id , string targetFramework = DefaultTargetFrameworkForBlazor )
434
442
{
435
443
InitPaths ( id ) ;
436
444
if ( Directory . Exists ( _projectDir ) )
437
445
Directory . Delete ( _projectDir , recursive : true ) ;
438
446
Directory . CreateDirectory ( _projectDir ) ;
439
- Directory . CreateDirectory ( Path . Combine ( _projectDir , ".nuget" ) ) ;
440
447
441
448
File . WriteAllText ( Path . Combine ( _projectDir , "nuget.config" ) ,
442
449
GetNuGetConfigWithLocalPackagesPath (
443
- Path . Combine ( BuildEnvironment . TestDataPath , NuGetConfigFileNameForDefaultFramework ) ,
450
+ GetNuGetConfigPathFor ( targetFramework ) ,
444
451
s_buildEnv . BuiltNuGetsPath ) ) ;
445
452
446
453
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)
497
504
protected ( CommandResult , string ) BlazorBuild ( BlazorBuildOptions options , params string [ ] extraArgs )
498
505
{
499
506
var res = BuildInternal ( options . Id , options . Config , publish : false , setWasmDevel : false , extraArgs ) ;
507
+ _testOutput . WriteLine ( $ "BlazorBuild, options.tfm: { options . TargetFramework } ") ;
500
508
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 ) ;
502
513
503
514
return res ;
504
515
}
@@ -507,7 +518,10 @@ public string CreateBlazorWasmTemplateProject(string id)
507
518
{
508
519
var res = BuildInternal ( options . Id , options . Config , publish : true , setWasmDevel : false , extraArgs ) ;
509
520
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 ) ;
511
525
512
526
if ( options . ExpectedFileType == NativeFilesType . AOT )
513
527
{
@@ -539,17 +553,18 @@ public string CreateBlazorWasmTemplateProject(string id)
539
553
540
554
CommandResult res = new DotNetCommand ( s_buildEnv , _testOutput )
541
555
. WithWorkingDirectory ( _projectDir ! )
556
+ . WithEnvironmentVariable ( "NUGET_PACKAGES" , _nugetPackagesDir )
542
557
. ExecuteWithCapturedOutput ( combinedArgs )
543
558
. EnsureSuccessful ( ) ;
544
559
545
560
return ( res , logPath ) ;
546
561
}
547
562
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 )
549
564
{
550
565
string label = forPublish ? "publish" : "build" ;
551
566
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 ) ;
553
568
554
569
string srcDir = type switch
555
570
{
@@ -590,7 +605,14 @@ static void AssertRuntimePackPath(string buildOutput, string targetFramework)
590
605
throw new XunitException ( $ "Runtime pack path doesn't match.{ Environment . NewLine } Expected: '{ expectedRuntimePackDir } '{ Environment . NewLine } Actual: '{ actualPath } '") ;
591
606
}
592
607
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 )
594
616
{
595
617
AssertFilesExist ( bundleDir , new [ ]
596
618
{
@@ -638,7 +660,7 @@ protected static void AssertDotNetWasmJs(string bundleDir, bool fromRuntimePack,
638
660
same : fromRuntimePack ) ;
639
661
}
640
662
641
- protected static void AssertDotNetJsSymbols ( string bundleDir , bool fromRuntimePack , string targetFramework = DefaultTargetFramework )
663
+ protected static void AssertDotNetJsSymbols ( string bundleDir , bool fromRuntimePack , string targetFramework )
642
664
=> AssertFile ( Path . Combine ( s_buildEnv . GetRuntimeNativeDir ( targetFramework ) , "dotnet.js.symbols" ) ,
643
665
Path . Combine ( bundleDir , "dotnet.js.symbols" ) ,
644
666
same : fromRuntimePack ) ;
@@ -690,11 +712,11 @@ protected static void AssertFile(string file0, string file1, string? label=null,
690
712
return result ;
691
713
}
692
714
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 )
694
716
{
695
- binFrameworkDir ??= FindBlazorBinFrameworkDir ( config , isPublish ) ;
717
+ binFrameworkDir ??= FindBlazorBinFrameworkDir ( config , isPublish , targetFramework ) ;
696
718
697
- AssertBlazorBootJson ( config , isPublish , binFrameworkDir : binFrameworkDir ) ;
719
+ AssertBlazorBootJson ( config , isPublish , targetFramework , binFrameworkDir : binFrameworkDir ) ;
698
720
AssertFile ( Path . Combine ( s_buildEnv . GetRuntimeNativeDir ( targetFramework ) , "dotnet.wasm" ) ,
699
721
Path . Combine ( binFrameworkDir , "dotnet.wasm" ) ,
700
722
"Expected dotnet.wasm to be same as the runtime pack" ,
@@ -709,9 +731,9 @@ protected void AssertBlazorBundle(string config, bool isPublish, bool dotnetWasm
709
731
same : dotnetWasmFromRuntimePack ) ;
710
732
}
711
733
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 )
713
735
{
714
- binFrameworkDir ??= FindBlazorBinFrameworkDir ( config , isPublish ) ;
736
+ binFrameworkDir ??= FindBlazorBinFrameworkDir ( config , isPublish , targetFramework ) ;
715
737
716
738
string bootJsonPath = Path . Combine ( binFrameworkDir , "blazor.boot.json" ) ;
717
739
Assert . True ( File . Exists ( bootJsonPath ) , $ "Expected to find { bootJsonPath } ") ;
@@ -728,7 +750,7 @@ protected void AssertBlazorBootJson(string config, bool isPublish, string? binFr
728
750
$ "{ msgPrefix } Could not find dotnet.*js in { bootJson } ") ;
729
751
}
730
752
731
- protected string FindBlazorBinFrameworkDir ( string config , bool forPublish , string framework = DefaultTargetFramework )
753
+ protected string FindBlazorBinFrameworkDir ( string config , bool forPublish , string framework = DefaultTargetFrameworkForBlazor )
732
754
{
733
755
string basePath = Path . Combine ( _projectDir ! , "bin" , config , framework ) ;
734
756
if ( forPublish )
@@ -1005,6 +1027,6 @@ public record BlazorBuildOptions
1005
1027
string Id ,
1006
1028
string Config ,
1007
1029
NativeFilesType ExpectedFileType ,
1008
- string TargetFramework = BuildTestBase . DefaultTargetFramework
1030
+ string TargetFramework = BuildTestBase . DefaultTargetFrameworkForBlazor
1009
1031
) ;
1010
1032
}
0 commit comments