Skip to content

Commit 6436336

Browse files
jonpryorjonathanpeppers
authored andcommitted
[Microsoft.Android.Templates] New files should open editor (#8623)
Fixes: https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1918037 Context: https://github.com/dotnet/templating/wiki/Reference-for-template.json Context: https://github.com/dotnet/templating/wiki/Post-Action-Registry#open-a-file-in-the-editor Within Visual Studio, if you: 1. Create a new .NET MAUI or .NET Android app, then 2. Go to the Solution Explorer, then 3. Right-click a folder, then click Add > New Item > Android, then 4. Double-click the **Android Activity** template. The expected result is that a new Android Activity based on the Android Activity template will be added to your solution *and opened in the editor*. Instead, a new Android Activity is added, but it is *not* opened. Update the `.template.config/template.json` files to contain a `postActions` section with a `openInEditor` id. This *should* cause Visual Studio to open the new files within the editor.
1 parent 2675256 commit 6436336

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/Microsoft.Android.Templates/android-activity/.template.config/template.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,18 @@
2121
"replaces": "AndroidApp1",
2222
"type": "parameter"
2323
}
24-
}
24+
},
25+
"postActions": [
26+
{
27+
"id": "openInEditor",
28+
"condition": "(HostIdentifier != \"dotnetcli\" && HostIdentifier != \"dotnetcli-preview\")",
29+
"description": "Opens Activity1.cs in the editor",
30+
"manualInstructions": [],
31+
"actionId": "84C0DA21-51C8-4541-9940-6CA19AF04EE6",
32+
"args": {
33+
"files": "0"
34+
},
35+
"continueOnError": true
36+
}
37+
]
2538
}

src/Microsoft.Android.Templates/android-layout/.template.config/template.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,18 @@
1414
"primaryOutputs": [
1515
{ "path": "Layout1.xml" }
1616
],
17-
"defaultName": "Layout1"
17+
"defaultName": "Layout1",
18+
"postActions": [
19+
{
20+
"id": "openInEditor",
21+
"condition": "(HostIdentifier != \"dotnetcli\" && HostIdentifier != \"dotnetcli-preview\")",
22+
"description": "Opens Layout1.xml in the editor",
23+
"manualInstructions": [],
24+
"actionId": "84C0DA21-51C8-4541-9940-6CA19AF04EE6",
25+
"args": {
26+
"files": "0"
27+
},
28+
"continueOnError": true
29+
}
30+
]
1831
}

0 commit comments

Comments
 (0)