maui
maui copied to clipboard
Fix <ApplicationTitle> encoding in maui-mobile template
Summary
There is a bug where certain characters (in this case &) which are not valid in MSBuild/XML are being used as the <ApplicationTitle> in the maui-mobile template. To fix this, I made <ApplicationTitle> use a custom symbol instead of the default name parameter. This symbol uses xmlEncode to allow it to work properly in the .csproj file.
Issues Fixed
Fixes: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2045293
Before/After
Before (using the project name Cats&Dogs):
After (using the project name Cats&Dogs2):
/azp run
Azure Pipelines successfully started running 1 pipeline(s).
Can we add a unit test? there's some msbuild project tests I think.
Thanks
@rmarinho
Can we add a unit test? there's some msbuild project tests I think.
Where? I looked at src\Templates\tests and don't see anything of value there.
FYI, I haven't built or done anything of actual coding in this repo. All I did for this fix was:
- Install maui workload via CLI.
- Created a new project using the name
Cats&Dogs, tried to run thedotnet publishcommand (like in the issue), and saw it fails. - Went into the
template-packsfolder and found the maui nupkg. - Extracted the contents, modified the
template.jsonand .csproj for maui-mobile, then dropped the modified files back into the nupkg again. - Did the same thing as Step 2 with the name
Cats&Dogs2, saw thatApplicationTitlewas encoded properly, and observed that publishing no longer errored for the reported reason.
We have a couple of them here
https://github.com/dotnet/maui/blob/222ca3ca088d199ff22adde8ca3ae82d9dba0b35/src/TestUtils/src/Microsoft.Maui.IntegrationTests/TemplateTests.cs#L6
Hi @MiYanni. We have added the "s/pr-needs-author-input" label to this issue, which indicates that we have an open question/action for you before we can take further action. This PRwill be closed automatically in 14 days if we do not hear back from you by then - please feel free to re-open it if you come back to this PR after that time.
I don't have cycles to work on a unit test for this issue. I've had the DevOps work item assigned to the MAUI team.
I tried the original repro and it seems still broken. I cloned this PR locally, built it, and ran dotnet new maui -n "𫓧龦唉丂荳◎℉㐁&ᠭᠤ སྲིད خەل ꌠ ᥕ᧞" (per the original bug), and the template was created, but then building it caused errors.
This is in the Build Output as an error:
1>C:\Users\elipton\.nuget\packages\microsoft.maui.resizetizer\8.0.7\buildTransitive\Microsoft.Maui.Resizetizer.After.targets(766,9): error : Could not find a part of the path 'E:\repos\BugRepros\maui22084encodeapptitle\𫓧龦唉丂荳◎℉%EE%80%B9㐁&ᠭᠤ སྲིད خەل ꌠ ᥕ᧞\Platforms\Windows\Package.appxmanifest'.
And then another error shows up only in the Error List:
Severity Code Description Project File Line Suppression State Details
Error (active) Could not find a part of the path 'E:\repos\BugRepros\maui22084encodeapptitle\𫓧龦唉丂荳◎℉%EE%80%B9㐁&ᠭᠤ སྲིད خەل ꌠ ᥕ᧞\Platforms\Android\AndroidManifest.xml'.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials, IWebProxy proxy, RequestCachePolicy cachePolicy)
at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn)
at System.Xml.XmlTextReaderImpl.FinishInitUriString()
at System.Xml.XmlReaderSettings.CreateReader(String inputUri, XmlParserContext inputContext)
at System.Xml.Linq.XDocument.Load(String uri, LoadOptions options)
at Xamarin.Android.Tasks.GetJavaPlatformJar.RunTask() 𫓧龦唉丂荳◎℉㐁&ᠭᠤ སྲིད خەل ꌠ ᥕ᧞ (net8.0-android) C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.95\tools\Xamarin.Android.Tooling.targets 100
And once I start opening other files in the project, such as XAML/C# files I get even more errors in the Error List:
Severity Code Description Project File Line Suppression State Details
Error XLS0414 The type 'maui:MauiWinUIApplication' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built. 𫓧龦唉丂荳◎℉㐁&ᠭᠤ སྲིད خەل ꌠ ᥕ᧞ E:\repos\BugRepros\maui22084encodeapptitle\𫓧龦唉丂荳◎℉㐁&ᠭᠤ སྲིད خەل ꌠ ᥕ᧞\Platforms\Windows\App.xaml 1
Error XLS0429 Undefined namespace. The 'using' URI refers to a namespace 'Microsoft.Maui' that could not be found. 𫓧龦唉丂荳◎℉㐁&ᠭᠤ སྲིད خەل ꌠ ᥕ᧞ E:\repos\BugRepros\maui22084encodeapptitle\𫓧龦唉丂荳◎℉㐁&ᠭᠤ སྲིད خەل ꌠ ᥕ᧞\Platforms\Windows\App.xaml 5
Error (active) CS0246 The type or namespace name 'ContentPage' could not be found (are you missing a using directive or an assembly reference?) 𫓧龦唉丂荳◎℉㐁&ᠭᠤ སྲིད خەل ꌠ ᥕ᧞ (net8.0-windows10.0.19041.0) E:\repos\BugRepros\maui22084encodeapptitle\𫓧龦唉丂荳◎℉%EE%80%B9㐁&ᠭᠤ སྲིད خەل ꌠ ᥕ᧞\MainPage.xaml.cs 3
Error (active) CS0103 The name 'InitializeComponent' does not exist in the current context 𫓧龦唉丂荳◎℉㐁&ᠭᠤ སྲིད خەل ꌠ ᥕ᧞ (net8.0-windows10.0.19041.0) E:\repos\BugRepros\maui22084encodeapptitle\𫓧龦唉丂荳◎℉%EE%80%B9㐁&ᠭᠤ སྲིད خەل ꌠ ᥕ᧞\MainPage.xaml.cs 9
Error (active) CS0103 The name 'CounterBtn' does not exist in the current context 𫓧龦唉丂荳◎℉㐁&ᠭᠤ སྲིད خەل ꌠ ᥕ᧞ (net8.0-windows10.0.19041.0) E:\repos\BugRepros\maui22084encodeapptitle\𫓧龦唉丂荳◎℉%EE%80%B9㐁&ᠭᠤ སྲིད خەل ꌠ ᥕ᧞\MainPage.xaml.cs 17
Error (active) CS0103 The name 'CounterBtn' does not exist in the current context 𫓧龦唉丂荳◎℉㐁&ᠭᠤ སྲིད خەل ꌠ ᥕ᧞ (net8.0-windows10.0.19041.0) E:\repos\BugRepros\maui22084encodeapptitle\𫓧龦唉丂荳◎℉%EE%80%B9㐁&ᠭᠤ སྲིད خەل ꌠ ᥕ᧞\MainPage.xaml.cs 19
Error (active) CS0103 The name 'SemanticScreenReader' does not exist in the current context 𫓧龦唉丂荳◎℉㐁&ᠭᠤ སྲིད خەل ꌠ ᥕ᧞ (net8.0-windows10.0.19041.0) E:\repos\BugRepros\maui22084encodeapptitle\𫓧龦唉丂荳◎℉%EE%80%B9㐁&ᠭᠤ སྲིད خەل ꌠ ᥕ᧞\MainPage.xaml.cs 21
Error (active) CS0103 The name 'CounterBtn' does not exist in the current context 𫓧龦唉丂荳◎℉㐁&ᠭᠤ སྲིད خەل ꌠ ᥕ᧞ (net8.0-windows10.0.19041.0) E:\repos\BugRepros\maui22084encodeapptitle\𫓧龦唉丂荳◎℉%EE%80%B9㐁&ᠭᠤ སྲིད خەل ꌠ ᥕ᧞\MainPage.xaml.cs 21
Also as a note, whatever fix we end up with needs to be applied to all the relevant templates: maui, maui-blazor, maui multi-project, and the net9-only maui-blazor-solution.
For the case of dotnet new maui -n "dogs & cats" it builds fine for all platforms, but when I run it on Android Emulator I get this runtime exception:
Microsoft.Maui.Controls.Xaml.XamlParseException
Message=Position 12:9. DataTemplateExtension: Could not locate type for local:MainPage.
Source=Microsoft.Maui.Controls.Xaml
StackTrace:
at Microsoft.Maui.Controls.Xaml.DataTemplateExtension.ProvideValue(IServiceProvider serviceProvider) in D:\a\_work\1\s\src\Controls\src\Xaml\MarkupExtensions\DataTemplateExtension.cs:line 27
at Microsoft.Maui.Controls.Xaml.DataTemplateExtension.Microsoft.Maui.Controls.Xaml.IMarkupExtension.ProvideValue(IServiceProvider serviceProvider) in D:\a\_work\1\s\src\Controls\src\Xaml\MarkupExtensions\DataTemplateExtension.cs:line 32
at Microsoft.Maui.Controls.Xaml.ApplyPropertiesVisitor.ProvideValue(Object& value, ElementNode node, Object source, XmlName propertyName) in D:\a\_work\1\s\src\Controls\src\Xaml\ApplyPropertiesVisitor.cs:line 286
And on Windows when I try to run it won't even let me and I get this error:
---------------------------
Microsoft Visual Studio
---------------------------
Unable to activate Windows Store app 'com.companyname.dogscats_9zz4h110yvjzm!App'. The activation request failed with error 'This application has failed to start because the application configuration is incorrect. Review the manifest file for possible errors. Reinstalling the application may fix this problem. For more details, please see the application event log'.
See help for advice on troubleshooting the issue.
---------------------------
OK Help
---------------------------
Hi @MiYanni.
It seems you haven't touched this PR for the last two weeks. To avoid accumulating old PRs, we're marking it as stale. As a result, it will be closed if no further activity occurs within 4 days of this comment. You can learn more about our Issue Management Policies here.
I won't be able to get to doing unit tests anytime soon for this. This is still a valid fix for at least one issue with your templates. @Eilon pointed out many other issues, but the MAUI team would need to investigate those.
Seems your bot is broken, as I commented and it never unmarked the PR as stale.
... I'll just let this fall off the plate. Up to you guys if you want to fix it.
Sorry I forgot to take the label off the issue, so the bot closed it again.
I think this PR has some good changes in it but per my testing it didn't seem to fix the entire issue as stated in the original repro, which is I think what we'd be looking for in order to merge it.
@Eilon Ah, I don't have any intention to fix the issue then. I only identified the immediate issue (which is still a problem) and fixed that. But the rest of the problems described are a chain of things that MAUI would need to investigate.
Tried this change on macOS where it doesn't have any effect, on Windows it does show the desired behavior. This seems like a weird behavior in the .NET templating engine so raised a bug here: https://github.com/dotnet/templating/issues/8052
Regardless even of this fixing the original issue yes or no
OK it turns out that the original repro that contains a multitude of Unicode characters is failing due to a System.Xml bug that I just logged: https://github.com/dotnet/runtime/issues/103532
So we can't fix that ourselves, presumably. I'll continue my testing by avoiding that particular issue and see if everything else is working.
I tried creating a project named only 𫓧 and it seems that something with the Android world simply does not allow non-ASCII characters in ANY part of the path. For example, Android Studio won't even let you create a project with non-ASCII characters:
If I create things manually in the .NET MAUI world and manually run the Android build tools, for example:
E:\repos\maui\bin\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.113\tools\aapt2.exe link -v --trace-folder "e:\android_trace" --manifest "E:\repos\BugRepros\𫓧\obj\Debug\net8.0-android\android\manifest\AndroidManifest.xml" --java C:\Users\elipton\AppData\Local\Temp\3t53hai1.0u0 --custom-package com.companyname --auto-add-overlay -I C:\Program Files (x86)\Android\android-sdk\platforms\android-34\android.jar -A "E:\repos\BugRepros\𫓧\obj\Debug\net8.0-android\assets" -o "E:\repos\BugRepros\𫓧\obj\Debug\net8.0-android\android\bin\packaged_resources"
Then you get this error (which has nothing to do with .NET MAUI) (and note the invalid Unicode/ASCII jumble in the path):
E:\repos\BugRepros\≡½ôº\obj\Debug\net8.0-android\android\manifest\AndroidManifest.xml: error: failed to load XML file: The system cannot find the file specified. (2).
And the Android tool trace folder output also indicates a Unicode/ASCII jumble by substituting the character with ≡½ôº
The error ultimately seems to come from this line in the Android build tools: https://android.googlesource.com/platform/frameworks/base/+/master/tools/aapt2/cmd/Link.cpp#290
And I've seen numerous mentions of this issue (and related ones) by other people:
- https://stackoverflow.com/questions/32171968/your-project-path-contains-non-ascii-characters-android-studio
- https://stackoverflow.com/questions/49212923/your-sdk-location-contains-non-ascii-characters-no-android-in-tools-menu
- https://github.com/dotnet/maui/issues/3005
I filed a bug on Google's issue tracker for this issue: https://issuetracker.google.com/issues/347706983
/azup run
/azp run
Azure Pipelines successfully started running 3 pipeline(s).
/azp run
Azure Pipelines successfully started running 3 pipeline(s).
/azp run
Azure Pipelines successfully started running 3 pipeline(s).
/azp run
Azure Pipelines successfully started running 3 pipeline(s).
/azp run
Azure Pipelines successfully started running 3 pipeline(s).
/azp run