From 944d656983b31c7a4ed53fdb2925fef633be836b Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Tue, 9 Jan 2024 18:51:57 -0500 Subject: [PATCH 1/2] [Microsoft.Android.Templates] New files should open editor 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. --- .../.template.config/template.json | 15 ++++++++++++++- .../android-layout/.template.config/template.json | 15 ++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.Android.Templates/android-activity/.template.config/template.json b/src/Microsoft.Android.Templates/android-activity/.template.config/template.json index b729622d9c3..3c95a4f76ba 100644 --- a/src/Microsoft.Android.Templates/android-activity/.template.config/template.json +++ b/src/Microsoft.Android.Templates/android-activity/.template.config/template.json @@ -21,5 +21,18 @@ "replaces": "AndroidApp1", "type": "parameter" } - } + }, + "postActions": [ + { + "id": "openInEditor", + "condition": "(HostIdentifier != \"dotnetcli\" && HostIdentifier != \"dotnetcli-preview\")", + "description": "Opens Activity1.cs in the editor", + "manualInstructions": [], + "actionId": "84C0DA21-51C8-4541-9940-6CA19AF04EE6", + "args": { + "files": "1" + }, + "continueOnError": true + } + ] } \ No newline at end of file diff --git a/src/Microsoft.Android.Templates/android-layout/.template.config/template.json b/src/Microsoft.Android.Templates/android-layout/.template.config/template.json index 2d1d8c72fb7..cfa1892c182 100644 --- a/src/Microsoft.Android.Templates/android-layout/.template.config/template.json +++ b/src/Microsoft.Android.Templates/android-layout/.template.config/template.json @@ -14,5 +14,18 @@ "primaryOutputs": [ { "path": "Layout1.xml" } ], - "defaultName": "Layout1" + "defaultName": "Layout1", + "postActions": [ + { + "id": "openInEditor", + "condition": "(HostIdentifier != \"dotnetcli\" && HostIdentifier != \"dotnetcli-preview\")", + "description": "Opens Layout1.xml in the editor", + "manualInstructions": [], + "actionId": "84C0DA21-51C8-4541-9940-6CA19AF04EE6", + "args": { + "files": "1" + }, + "continueOnError": true + } + ] } \ No newline at end of file From 5c29ee4c575f0285670cf793b1f35d9fef603f4c Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Tue, 9 Jan 2024 20:47:30 -0500 Subject: [PATCH 2/2] Use path index 0, not 1. Thanks to @pjcollins for testing! --- .../android-activity/.template.config/template.json | 2 +- .../android-layout/.template.config/template.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.Android.Templates/android-activity/.template.config/template.json b/src/Microsoft.Android.Templates/android-activity/.template.config/template.json index 3c95a4f76ba..be928b8a921 100644 --- a/src/Microsoft.Android.Templates/android-activity/.template.config/template.json +++ b/src/Microsoft.Android.Templates/android-activity/.template.config/template.json @@ -30,7 +30,7 @@ "manualInstructions": [], "actionId": "84C0DA21-51C8-4541-9940-6CA19AF04EE6", "args": { - "files": "1" + "files": "0" }, "continueOnError": true } diff --git a/src/Microsoft.Android.Templates/android-layout/.template.config/template.json b/src/Microsoft.Android.Templates/android-layout/.template.config/template.json index cfa1892c182..c3cea066474 100644 --- a/src/Microsoft.Android.Templates/android-layout/.template.config/template.json +++ b/src/Microsoft.Android.Templates/android-layout/.template.config/template.json @@ -23,7 +23,7 @@ "manualInstructions": [], "actionId": "84C0DA21-51C8-4541-9940-6CA19AF04EE6", "args": { - "files": "1" + "files": "0" }, "continueOnError": true }