Skip to content

Commit e707f98

Browse files
authored
[release/7.0][wasm] Update templates to add framework argument (#76123)
* [wasm] Update templates to add framework argument * [wasm] Add tests for templates creating with specific tfm
1 parent 992005a commit e707f98

File tree

4 files changed

+58
-9
lines changed

4 files changed

+58
-9
lines changed

src/mono/wasm/templates/templates/browser/.template.config/template.json

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,33 @@
22
"$schema": "http://json.schemastore.org/template",
33
"author": "Microsoft",
44
"classifications": [ "Web", "WebAssembly", "Browser" ],
5-
"identity": "WebAssembly.Browser",
5+
"generatorVersions": "[1.0.0.0-*)",
6+
"groupIdentity": "WebAssembly.Browser",
7+
"precedence": 7000,
8+
"identity": "WebAssembly.Browser.7.0",
9+
"description": "WebAssembly Browser App",
610
"name": "WebAssembly Browser App",
711
"shortName": "wasmbrowser",
812
"sourceName": "browser.0",
913
"preferNameDirectory": true,
1014
"tags": {
1115
"language": "C#",
1216
"type": "project"
17+
},
18+
"symbols": {
19+
"framework": {
20+
"type": "parameter",
21+
"description": "The target framework for the project.",
22+
"datatype": "choice",
23+
"choices": [
24+
{
25+
"choice": "net7.0",
26+
"description": "Target net7.0",
27+
"displayName": ".NET 7.0"
28+
}
29+
],
30+
"defaultValue": "net7.0",
31+
"displayName": "framework"
32+
}
1333
}
1434
}

src/mono/wasm/templates/templates/console/.template.config/template.json

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,32 @@
22
"$schema": "http://json.schemastore.org/template",
33
"author": "Microsoft",
44
"classifications": [ "Web", "WebAssembly", "Console" ],
5-
"identity": "WebAssembly.Console",
5+
"groupIdentity": "WebAssembly.Console",
6+
"precedence": 7000,
7+
"identity": "WebAssembly.Console.7.0",
8+
"description": "WebAssembly Console App",
69
"name": "WebAssembly Console App",
710
"shortName": "wasmconsole",
811
"sourceName": "console.0",
912
"preferNameDirectory": true,
1013
"tags": {
1114
"language": "C#",
1215
"type": "project"
16+
},
17+
"symbols": {
18+
"framework": {
19+
"type": "parameter",
20+
"description": "The target framework for the project.",
21+
"datatype": "choice",
22+
"choices": [
23+
{
24+
"choice": "net7.0",
25+
"description": "Target net7.0",
26+
"displayName": ".NET 7.0"
27+
}
28+
],
29+
"defaultValue": "net7.0",
30+
"displayName": "framework"
31+
}
1332
}
1433
}

src/tests/BuildWasmApps/Wasm.Build.Tests/BuildTestBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ private static string GetNuGetConfigWithLocalPackagesPath(string templatePath, s
442442
return contents.Replace(s_nugetInsertionTag, $@"<add key=""nuget-local"" value=""{localNuGetsPath}"" />");
443443
}
444444

445-
public string CreateWasmTemplateProject(string id, string template = "wasmbrowser")
445+
public string CreateWasmTemplateProject(string id, string template = "wasmbrowser", string extraArgs = "")
446446
{
447447
InitPaths(id);
448448
InitProjectDir(id);
@@ -459,7 +459,7 @@ public string CreateWasmTemplateProject(string id, string template = "wasmbrowse
459459

460460
new DotNetCommand(s_buildEnv, _testOutput, useDefaultArgs: false)
461461
.WithWorkingDirectory(_projectDir!)
462-
.ExecuteWithCapturedOutput($"new {template}")
462+
.ExecuteWithCapturedOutput($"new {template} {extraArgs}")
463463
.EnsureSuccessful();
464464

465465
return Path.Combine(_projectDir!, $"{id}.csproj");

src/tests/BuildWasmApps/Wasm.Build.Tests/WasmTemplateTests.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,18 @@ public void ConsoleBuildThenPublish(string config)
182182
[InlineData("Debug", true)]
183183
[InlineData("Release", false)]
184184
[InlineData("Release", true)]
185-
public void ConsoleBuildAndRun(string config, bool relinking)
185+
public void ConsoleBuildAndRunDefault(string config, bool relinking)
186+
=> ConsoleBuildAndRun(config, relinking, string.Empty);
187+
188+
[ConditionalTheory(typeof(BuildTestBase), nameof(IsUsingWorkloads))]
189+
[InlineData("Debug", "-f net7.0")]
190+
public void ConsoleBuildAndRunForSpecificTFM(string config, string extraNewArgs)
191+
=> ConsoleBuildAndRun(config, false, extraNewArgs);
192+
193+
private void ConsoleBuildAndRun(string config, bool relinking, string extraNewArgs)
186194
{
187195
string id = $"{config}_{Path.GetRandomFileName()}";
188-
string projectFile = CreateWasmTemplateProject(id, "wasmconsole");
196+
string projectFile = CreateWasmTemplateProject(id, "wasmconsole", extraNewArgs);
189197
string projectName = Path.GetFileNameWithoutExtension(projectFile);
190198

191199
UpdateProgramCS();
@@ -432,12 +440,14 @@ public async Task BlazorRunTest()
432440
Assert.Equal("Current count: 1", txt);
433441
}
434442

435-
[ConditionalFact(typeof(BuildTestBase), nameof(IsUsingWorkloads))]
436-
public async Task BrowserTest()
443+
[ConditionalTheory(typeof(BuildTestBase), nameof(IsUsingWorkloads))]
444+
[InlineData("")]
445+
[InlineData("-f net7.0")]
446+
public async Task BrowserBuildAndRun(string extraNewArgs)
437447
{
438448
string config = "Debug";
439449
string id = $"browser_{config}_{Path.GetRandomFileName()}";
440-
CreateWasmTemplateProject(id, "wasmbrowser");
450+
CreateWasmTemplateProject(id, "wasmbrowser", extraNewArgs);
441451

442452
// var buildArgs = new BuildArgs(projectName, config, false, id, null);
443453
// buildArgs = ExpandBuildArgs(buildArgs);

0 commit comments

Comments
 (0)