Skip to content

[templates] Fix applicationId template option#13509

Merged
Eilon merged 2 commits into
mainfrom
fix-13297
Mar 2, 2023
Merged

[templates] Fix applicationId template option#13509
Eilon merged 2 commits into
mainfrom
fix-13297

Conversation

@jknaudt21
Copy link
Copy Markdown
Contributor

@jknaudt21 jknaudt21 commented Feb 23, 2023

Description of Change

We prevent the templating engine from matching the AppID to the App's name (the sourceName). This allows the applicationId parameter to work as expected when doing dotnet new -ap com.my.name. I also make sure that if we're using the (lowercased) app name as an AppID in case no parameter is passed.

The changes required some tricks using the templating engine. Mainly:

  • Creating a separate variable (symbol) for the lowercased app name
  • Creating a new symbol defaultAppId that is the concatenation of "com.company." with the lowercased app name
  • Use the coalescing generator to evaluate the finalAppID. The result depends on whether the applicationId parameter was passed by the user. If the applicationId is null (i.e not given), we use the defaultAppId; otherwise we use whatever the user provided.

Issues Fixed

fixes #13297

By preventing the templating engine from matching the AppID to the App's name (the sourceName), we allow the parameter to work
@jsuarezruiz jsuarezruiz added the area-templates Project templates, Item Templates for Blazor and MAUI label Feb 23, 2023
@jknaudt21 jknaudt21 marked this pull request as ready for review February 24, 2023 18:00
@jknaudt21 jknaudt21 requested a review from a team as a code owner February 24, 2023 18:00
@jknaudt21 jknaudt21 requested a review from Redth February 24, 2023 18:00
@Eilon
Copy link
Copy Markdown
Contributor

Eilon commented Feb 28, 2023

@jknaudt21 very nice! Can you confirm what happens with:

  1. dotnet new maui
  2. dotnet new maui -o FooBar_Baz.Banana

I want to make sure that those cases are also handled reasonably well. Or will they just get the default value com.companyname.mauiapp unless it's explicitly set at project creation time?

@jknaudt21

This comment was marked as outdated.

@jknaudt21 jknaudt21 requested a review from Eilon March 1, 2023 01:32
@jknaudt21
Copy link
Copy Markdown
Contributor Author

jknaudt21 commented Mar 1, 2023

I'm looking into seeing if something can be done with a symbol generator. https://github.com/dotnet/templating/wiki/Available-Symbols-Generators.

Marking PR as a draft until I arrive at a conclusion.

Edit: a solution was found that is the best of both worlds :)

@jknaudt21 jknaudt21 marked this pull request as draft March 1, 2023 22:12
@jknaudt21 jknaudt21 marked this pull request as ready for review March 2, 2023 00:04
Copy link
Copy Markdown
Contributor

@Eilon Eilon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-templates Project templates, Item Templates for Blazor and MAUI fixed-in-8.0.0-preview.3.8149 Look for this fix in 8.0.0-preview.3.8149!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Template option '--applicationId' doesn't work in standard maui template

4 participants