@@ -25,7 +25,8 @@ namespace Wasm.Build.Tests
25
25
{
26
26
public abstract class BuildTestBase : IClassFixture < SharedBuildPerTestClassFixture > , IDisposable
27
27
{
28
- protected const string s_targetFramework = "net6.0" ;
28
+ public const string DefaultTargetFramework = "net7.0" ;
29
+ public static readonly string NuGetConfigFileNameForDefaultFramework = $ "nuget7.config";
29
30
protected static readonly bool s_skipProjectCleanup ;
30
31
protected static readonly string s_xharnessRunnerCommand ;
31
32
protected string ? _projectDir ;
@@ -128,7 +129,7 @@ protected string RunAndTestWasmApp(BuildArgs buildArgs,
128
129
int expectedExitCode = 0 ,
129
130
string ? args = null ,
130
131
Dictionary < string , string > ? envVars = null ,
131
- string targetFramework = "net6.0" )
132
+ string targetFramework = DefaultTargetFramework )
132
133
{
133
134
buildDir ??= _projectDir ;
134
135
envVars ??= new ( ) ;
@@ -246,14 +247,14 @@ protected static void InitProjectDir(string dir)
246
247
File . WriteAllText ( Path . Combine ( dir , "Directory.Build.props" ) , s_buildEnv . DirectoryBuildPropsContents ) ;
247
248
File . WriteAllText ( Path . Combine ( dir , "Directory.Build.targets" ) , s_buildEnv . DirectoryBuildTargetsContents ) ;
248
249
249
- File . Copy ( Path . Combine ( BuildEnvironment . TestDataPath , "nuget6.config" ) , Path . Combine ( dir , "nuget.config" ) ) ;
250
+ File . Copy ( Path . Combine ( BuildEnvironment . TestDataPath , NuGetConfigFileNameForDefaultFramework ) , Path . Combine ( dir , "nuget.config" ) ) ;
250
251
Directory . CreateDirectory ( Path . Combine ( dir , ".nuget" ) ) ;
251
252
}
252
253
253
254
protected const string SimpleProjectTemplate =
254
255
@$ "<Project Sdk=""Microsoft.NET.Sdk"">
255
256
<PropertyGroup>
256
- <TargetFramework>{ s_targetFramework } </TargetFramework>
257
+ <TargetFramework>{ DefaultTargetFramework } </TargetFramework>
257
258
<OutputType>Exe</OutputType>
258
259
<WasmGenerateRunV8Script>true</WasmGenerateRunV8Script>
259
260
<WasmMainJSPath>test-main.js</WasmMainJSPath>
@@ -342,7 +343,7 @@ protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProp
342
343
343
344
if ( options . ExpectSuccess )
344
345
{
345
- string bundleDir = Path . Combine ( GetBinDir ( config : buildArgs . Config , targetFramework : options . TargetFramework ?? "net6.0" ) , "AppBundle" ) ;
346
+ string bundleDir = Path . Combine ( GetBinDir ( config : buildArgs . Config , targetFramework : options . TargetFramework ?? DefaultTargetFramework ) , "AppBundle" ) ;
346
347
AssertBasicAppBundle ( bundleDir , buildArgs . ProjectName , buildArgs . Config , options . MainJS ?? "test-main.js" , options . HasV8Script , options . HasIcudt , options . DotnetWasmFromRuntimePack ?? ! buildArgs . AOT ) ;
347
348
}
348
349
@@ -367,7 +368,7 @@ public void InitBlazorWasmProjectDir(string id)
367
368
Directory . CreateDirectory ( _projectDir ) ;
368
369
Directory . CreateDirectory ( Path . Combine ( _projectDir , ".nuget" ) ) ;
369
370
370
- File . Copy ( Path . Combine ( BuildEnvironment . TestDataPath , "nuget6.config" ) , Path . Combine ( _projectDir , "nuget.config" ) ) ;
371
+ File . Copy ( Path . Combine ( BuildEnvironment . TestDataPath , NuGetConfigFileNameForDefaultFramework ) , Path . Combine ( _projectDir , "nuget.config" ) ) ;
371
372
File . Copy ( Path . Combine ( BuildEnvironment . TestDataPath , "Blazor.Directory.Build.props" ) , Path . Combine ( _projectDir , "Directory.Build.props" ) ) ;
372
373
File . Copy ( Path . Combine ( BuildEnvironment . TestDataPath , "Blazor.Directory.Build.targets" ) , Path . Combine ( _projectDir , "Directory.Build.targets" ) ) ;
373
374
}
@@ -395,22 +396,22 @@ public string CreateBlazorWasmTemplateProject(string id)
395
396
return Path . Combine ( _projectDir ! , $ "{ id } .csproj") ;
396
397
}
397
398
398
- protected ( CommandResult , string ) BlazorBuild ( string id , string config , NativeFilesType expectedFileType , params string [ ] extraArgs )
399
+ protected ( CommandResult , string ) BlazorBuild ( BlazorBuildOptions options , params string [ ] extraArgs )
399
400
{
400
- var res = BuildInternal ( id , config , publish : false , extraArgs ) ;
401
- AssertDotNetNativeFiles ( expectedFileType , config , forPublish : false ) ;
402
- AssertBlazorBundle ( config , isPublish : false , dotnetWasmFromRuntimePack : expectedFileType == NativeFilesType . FromRuntimePack ) ;
401
+ var res = BuildInternal ( options . Id , options . Config , publish : false , extraArgs ) ;
402
+ AssertDotNetNativeFiles ( options . ExpectedFileType , options . Config , forPublish : false , targetFramework : options . TargetFramework ) ;
403
+ AssertBlazorBundle ( options . Config , isPublish : false , dotnetWasmFromRuntimePack : options . ExpectedFileType == NativeFilesType . FromRuntimePack ) ;
403
404
404
405
return res ;
405
406
}
406
407
407
- protected ( CommandResult , string ) BlazorPublish ( string id , string config , NativeFilesType expectedFileType , params string [ ] extraArgs )
408
+ protected ( CommandResult , string ) BlazorPublish ( BlazorBuildOptions options , params string [ ] extraArgs )
408
409
{
409
- var res = BuildInternal ( id , config , publish : true , extraArgs ) ;
410
- AssertDotNetNativeFiles ( expectedFileType , config , forPublish : true ) ;
411
- AssertBlazorBundle ( config , isPublish : true , dotnetWasmFromRuntimePack : expectedFileType == NativeFilesType . FromRuntimePack ) ;
410
+ var res = BuildInternal ( options . Id , options . Config , publish : true , extraArgs ) ;
411
+ AssertDotNetNativeFiles ( options . ExpectedFileType , options . Config , forPublish : true , targetFramework : options . TargetFramework ) ;
412
+ AssertBlazorBundle ( options . Config , isPublish : true , dotnetWasmFromRuntimePack : options . ExpectedFileType == NativeFilesType . FromRuntimePack ) ;
412
413
413
- if ( expectedFileType == NativeFilesType . AOT )
414
+ if ( options . ExpectedFileType == NativeFilesType . AOT )
414
415
{
415
416
// check for this too, so we know the format is correct for the negative
416
417
// test for jsinterop.webassembly.dll
@@ -445,10 +446,10 @@ public string CreateBlazorWasmTemplateProject(string id)
445
446
return ( res , logPath ) ;
446
447
}
447
448
448
- protected void AssertDotNetNativeFiles ( NativeFilesType type , string config , bool forPublish )
449
+ protected void AssertDotNetNativeFiles ( NativeFilesType type , string config , bool forPublish , string targetFramework = DefaultTargetFramework )
449
450
{
450
451
string label = forPublish ? "publish" : "build" ;
451
- string objBuildDir = Path . Combine ( _projectDir ! , "obj" , config , "net6.0" , "wasm" , forPublish ? "for-publish" : "for-build" ) ;
452
+ string objBuildDir = Path . Combine ( _projectDir ! , "obj" , config , targetFramework , "wasm" , forPublish ? "for-publish" : "for-build" ) ;
452
453
string binFrameworkDir = FindBlazorBinFrameworkDir ( config , forPublish ) ;
453
454
454
455
string srcDir = type switch
@@ -630,7 +631,7 @@ protected void AssertBlazorBootJson(string config, bool isPublish, string? binFr
630
631
$ "{ msgPrefix } Could not find dotnet.*js in { bootJson } ") ;
631
632
}
632
633
633
- protected string FindBlazorBinFrameworkDir ( string config , bool forPublish , string framework = "net6.0" )
634
+ protected string FindBlazorBinFrameworkDir ( string config , bool forPublish , string framework = DefaultTargetFramework )
634
635
{
635
636
string basePath = Path . Combine ( _projectDir ! , "bin" , config , framework ) ;
636
637
if ( forPublish )
@@ -652,14 +653,14 @@ private string FindSubDirIgnoringCase(string parentDir, string dirName)
652
653
return first ?? Path . Combine ( parentDir , dirName ) ;
653
654
}
654
655
655
- protected string GetBinDir ( string config , string targetFramework = s_targetFramework , string ? baseDir = null )
656
+ protected string GetBinDir ( string config , string targetFramework = DefaultTargetFramework , string ? baseDir = null )
656
657
{
657
658
var dir = baseDir ?? _projectDir ;
658
659
Assert . NotNull ( dir ) ;
659
660
return Path . Combine ( dir ! , "bin" , config , targetFramework , "browser-wasm" ) ;
660
661
}
661
662
662
- protected string GetObjDir ( string config , string targetFramework = s_targetFramework , string ? baseDir = null )
663
+ protected string GetObjDir ( string config , string targetFramework = DefaultTargetFramework , string ? baseDir = null )
663
664
{
664
665
var dir = baseDir ?? _projectDir ;
665
666
Assert . NotNull ( dir ) ;
@@ -885,4 +886,12 @@ public record BuildProjectOptions
885
886
string ? TargetFramework = null ,
886
887
string ? MainJS = null
887
888
) ;
889
+
890
+ public record BlazorBuildOptions
891
+ (
892
+ string Id ,
893
+ string Config ,
894
+ NativeFilesType ExpectedFileType ,
895
+ string TargetFramework = BuildTestBase . DefaultTargetFramework
896
+ ) ;
888
897
}
0 commit comments