-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
We have recent issue reported to our repo related to maui-blazor. Reported issue is: dotnet/templating#3666
I made some checks below:
-
I checked the templates and it appears that
slnis not part of templates anymore. Could you please confirm? -
Could you please check if
sourceNameyou are using in templates is safe for default forms?
https://github.com/dotnet/templating/wiki/Naming-and-default-value-forms
Template engine applies 5 forms to the source name:
- identity - no transformation
- safe namespace
string workingValue = Regex.Replace(value, @"(^\s+|\s+$)", "");
workingValue = Regex.Replace(workingValue, @"(((?<=\.)|^)((?=\d)|\.)|[^\w\.])|(\.$)", "_");
- safe class name
string workingValue = Regex.Replace(value, @"(^\s+|\s+$)", "");
workingValue = Regex.Replace(workingValue, @"(((?<=\.)|^)(?=\d)|\W)", "_");
- lower safe namespace and lower safe class name (same as above + ToLowerInvariant)
The source name you chose in template.json should provide different results for the form above, similar to the name mentioned in https://github.com/dotnet/templating/wiki/Naming-and-default-value-forms:
| Transform | Input | Output |
|---|---|---|
| Identity | Template.1 | Template.1 |
| Namespace | Template.1 | Template._1 |
| Class Name | Template.1 | Template__1 |
| Lowercase Namespace | Template.1 | template._1 |
| Lowercase Class Name | Template.1 | template__1 |
When sourceName is used in namespaces and class names, corresponding form should be used instead.
If the sourceName chosen is not safe, i.e. forms transformation results in same result, it's not guaranteed that correct form will be used when template engine replaces the values. This happened for the issue above:
MauiApp1is same for identity, namespace, and class name forms- user entered
Maui-Blazor-Dash, which results inMaui-Blazor-Dash,Maui_Blazor_Dash,Maui_Blazor_Dashrespectively - template engine picked up one of latter 2 for all replacements: while it is correct for namespace, it is not correct for replacements made in solution files, where
Maui-Blazor-Dashshould have been used.
While some other templates have same issue in sourceName, usually it is ok to use it if sourceName is only used in namespace for replacement, however it is not that case for maui, as sourceName is not used only for namespaces.