Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[templates] add ide.host.json files #7349

Merged
merged 1 commit into from
Sep 12, 2022

Conversation

jonathanpeppers
Copy link
Member

@jonathanpeppers jonathanpeppers commented Sep 6, 2022

Fixes: #7315
Fixes: #7231

This makes our item templates useable from inside Visual Studio, as it should allow them to show up in a new Android category in the "Add New Item" dialog.

Fixes: dotnet#7315

This makes our item templates useable from inside Visual Studio, as it
should allow them to show up in a new `Android` category in the "Add
New Item" dialog.
@jonathanpeppers
Copy link
Member Author

@jonpryor a few questions on this one:

They also require the Microsoft.VisualStudio.ComponentGroup.Maui.All component, but that doesn't really make sense? This component contains the Android workload and our templates.

@jonathanpeppers
Copy link
Member Author

The answer to all these is "no":

They also require the Microsoft.VisualStudio.ComponentGroup.Maui.All component, but that doesn't really make sense? This component contains the Android workload and our templates.

I manually tested by downloading Microsoft.Android.Templates.33.0.0-ci.pr.gh7349.163.nupkg and dropped it in:

C:\Program Files\dotnet\template-packs

Next edit C:\Program Files\dotnet\sdk-manifests\7.0.100-rc.1\microsoft.net.sdk.android\WorkloadManifest.json and change the version number:

    "Microsoft.Android.Templates": {
      "kind": "template",
      "version": "33.0.0-ci.pr.gh7349.163"
    }

Create a new net7.0-android app, and these items show up:

image

Then in a MAUI app:

image

@jonathanpeppers jonathanpeppers marked this pull request as ready for review September 7, 2022 20:50
jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this pull request Sep 9, 2022
After working on dotnet#7349, I found some really odd behavior if you name
an Android layout, `my_cool_layout.xml`.

VS appears to generate:

    <?xml version="1.0" encoding="utf-8"?>
    <Linearmy_cool_layout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:my_cool_layout_width="match_parent"
        android:my_cool_layout_height="match_parent">

    </Linearmy_cool_layout>

This is completely broken! It appears that anywhere the word `Layout`
was replaced with `my_cool_layout`. I also get the same behavior with
`dotnet new android-layout -n my_cool_layout`.

To solve this issue, I made the default name `Layout1`, so that
`<LinearLayout/>` and `android:layout_width`, are not replaced.

Now I get a `my_cool_layout.xml` with the contents:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </LinearLayout>

Secondly, the `android-activity` template if you run:

    dotnet new android-activity -n MyActivity

It will generate:

    [Activity(Label = "@string/app_name", MainLauncher = true)]
    public class MyActivity : Activity

Let's replace the label with the name passed in, and remove
`MainLauncher=true`, so we instead get:

    [Activity(Label = "MyActivity")]
    public class MyActivity : Activity

I think this will prevent confusion with multiple app launchers, etc.
@jonpryor
Copy link
Member

jonpryor commented Sep 9, 2022

@mrward: would you be able to take a look at this?

@mrward
Copy link

mrward commented Sep 9, 2022

Looks mostly fine to me. The layout file seems to be flagged as C#. But that seems to match what is in the template.json file:

https://github.com/xamarin/xamarin-android/blob/main/src/Microsoft.Android.Templates/android-layout/.template.config/template.json#L8

image
image
image
image

@jonathanpeppers
Copy link
Member Author

Hmm, even the MAUI "page" templates that are .xaml specify C# here:

https://github.com/dotnet/maui/blob/9a323ef559437aebfe27d91db6d7bebd1ba3d82f/src/Templates/src/templates/maui-contentpage-xaml/.template.config/template.json#L11

So we should change this to XML instead? Then the text would change here:

image

@mrward
Copy link

mrward commented Sep 9, 2022

For some reason I added a check to VS Mac that ignored every item template that was not C# language (I think I copied what WebTools was doing but will have to check). So for now I suggest it is left as C#.

@jonpryor jonpryor merged commit 861b5f1 into dotnet:main Sep 12, 2022
@jonathanpeppers jonathanpeppers deleted the ide.host.json branch September 12, 2022 19:21
jonathanpeppers added a commit that referenced this pull request Sep 12, 2022
After working on #7349, I found some really odd behavior if you name
an Android layout, `my_cool_layout.xml`.

VS appears to generate:

    <?xml version="1.0" encoding="utf-8"?>
    <Linearmy_cool_layout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:my_cool_layout_width="match_parent"
        android:my_cool_layout_height="match_parent">

    </Linearmy_cool_layout>

This is completely broken! It appears that anywhere the word `Layout`
was replaced with `my_cool_layout`. I also get the same behavior with
`dotnet new android-layout -n my_cool_layout`.

To solve this issue, I made the default name `Layout1`, so that
`<LinearLayout/>` and `android:layout_width`, are not replaced.

Now I get a `my_cool_layout.xml` with the contents:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </LinearLayout>

Secondly, the `android-activity` template if you run:

    dotnet new android-activity -n MyActivity

It will generate:

    [Activity(Label = "@string/app_name", MainLauncher = true)]
    public class MyActivity : Activity

Let's replace the label with the name passed in, and remove
`MainLauncher=true`, so we instead get:

    [Activity(Label = "MyActivity")]
    public class MyActivity : Activity

I think this will prevent confusion with multiple app launchers, etc.
grendello added a commit to grendello/xamarin-android that referenced this pull request Sep 13, 2022
* main:
  [templates] fix broken/wrong item template contents (dotnet#7366)
  [tests] export $DOTNET_gcServer as 0 (dotnet#7363)
  [templates] add `ide.host.json` files (dotnet#7349)
@hamiddd1980
Copy link

Hi.
I have updated my VS to latest version : Version 17.4.0 Preview 4.0
but in contrast to Xamarin.Android, there are only 2 templates available for .NET Android project.
is microsoft team going to add more items to .Net Android Templates?(at least like Xamarin.Android)

xam

@jonathanpeppers
Copy link
Member Author

The templates we have for .NET 6+ are what they are, and we would add more based on customer feedback.

Can you suggest a feature here? And folks can upvote and help us prioritize:

image

Make to say ".NET 6 Android", ".NET 6 iOS", etc. to mention what platforms and templates you need/find missing.

@github-actions github-actions bot locked and limited conversation to collaborators Jan 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Templates need to provide ide.host.json files Android Items Template is missing for .Net Android project
4 participants