Announcing .NET MAUI Preview 7
.NET 6 Preview 7 is now available, and we have introduced all new layouts for .NET Multi-platform App UI (MAUI). This is a significant change for performance and reliability. We are excited to also introduce some new accessibility focused capabilities based on the new SemanticService, font scaling options, compatibility support for Xamarin.Forms Effects, and more.
New Layouts
Up to now the layouts you’ve been using in .NET MAUI are the Xamarin.Forms layouts that were made aware of how to size and position both renderers and the new handler based controls. We began with this approach in order to quickly put UI on screen and focus our efforts on completing our library of UI 40 controls, and to prove out our ability to be compatible with projects migration from Xamarin.Forms. At the same time, we have been building optimized layouts based on a new LayoutManager approach employing our 7 years of Xamarin.Forms layout learning to optimize for consistency, performance, and maintainability.
In this preview, the old layouts are now only to be found in the Microsoft.Maui.Controls.Compatibility namespace, and the new layouts are enabled by default as:
- Grid
- FlexLayout
- StackLayout
- HorizontalStackLayout
- VerticalStackLayout
StackLayout now wraps two layouts focused on horizontal and vertical orientations. We recommend choosing the one that fits your layout need. The StackLayout still has an orientation property you can set, and in some cases this is essential when your adaptive layouts my change orientation based on screen size or device idiom.
Each layout has an accompanying LayoutManager responsible for measuring and positioning views. The Measure method takes height and width constraints, and is responsible for measuring all of hte layout’s children. The ArrangeChildren then sets the size and position of each view according to the rules of the layout. For very advanced cases, you may override the CreateLayoutManager method of a layout to provide a custom implementation of ILayoutManager.
One of the immediate updates you’ll noticed is the leveling of default spacing values on these layouts: 0. If you have used the legacy layouts, then you are already aware of different, arbitrary values previously set there. Zero sets a more clear expectation, and directs you to set your preferred values that meet your design needs. For convenience, set these starting values in your global styles:
<ResourceDictionary>
<Style TargetType="StackLayout">
<Setter Property="Spacing" Value="6"/>
</Style>
<Style TargetType="Grid">
<Setter Property="ColumnSpacing" Value="6"/>
<Setter Property="RowSpacing" Value="6"/>
</Style>
</ResourceDictionary>
AbsoluteLayout
and RelativeLayout
now exist only in the compatibility namespace, and we recommend you closely consider whether you really need to use them or not. Where possible, use one of the layouts listed above. In the meantime, you can update your code to use them by adding the new namespace, and prefixing your XAML references:
<ContentPage
xmlns:cmp="clr-namespace:Microsoft.Maui.Controls.Compatibility;assembly=Microsoft.Maui.Controls"
...
>
<cmp:AbsoluteLayout>
...
</cmp:AbsoluteLayout>
</ContentPage>
The .NET Upgrade Assistant is being updated for all of these changes, and we’ll do our best to guide you through them, if not handle them for you during the upgrade process.
We will be giving a lot of focus to polishing up these new layouts through the next several sprints, so please give them a look and file any issues you observe as you explore using them.
Accessibility Changes and Improvements
We meet monthly with several developers across a variety of companies heavily invested in delivering applications that meet the highest accessibility rating. From these meetings we have made a few changes and additions to our accessibility support making it easier for everyone to product accessible apps.
TabIndex and IsTabStop Removed
TabIndex and IsTabStop properties were introduced in Xamarin.Forms to help developers control the order in which UI elements would be read by a screen reader. In practice, they ended up being confusing and not meeting that need. In .NET MAUI we recommend a thoughtful design approach that orders your UI as you would want it to be read, rather than looking for programmatic ways to manipulate the structure of your interface. For cases when you must take control over the order, we recommend the community toolkit’s SemanticOrderView
which will be available in the .NET MAUI version of the same.
SetSemanticFocus and Announce
Part of the new SemanticExtensions
class, we have added a new SetSemanticFocus
method allows you to move screen reader focus to a specific element. Compare this to VisualElement.Focus
which sets input focus.
<VerticalStackLayout>
<Label
Text="Explore SemanticExtensions below"
TextColor="RoyalBlue"
FontAttributes="Bold"
FontSize="16"
Margin="0,10"/>
<Button
Text="Click to set semantic focus to label below"
FontSize="14"
Clicked="SetSemanticFocusButton_Clicked"/>
<Label
x:Name="semanticFocusLabel"
Text="Label receiving semantic focus"
FontSize="14"/>
</VerticalStackLayout>
private void SetSemanticFocusButton_Clicked(object sender, System.EventArgs e)
{
semanticFocusLabel.SetSemanticFocus();
}
Within Essentials we have added another new method, Announce
, which sets the text to be announced by the screen reader. On a button click, for example, you can trigger the following important message to be read:
void Announce_Clicked(object sender, EventArgs e)
{
SemanticScreenReader.Announce("Make accessible apps with .NET MAUI");
}
Font Scaling
All controls across all platforms now have font scaling enabled by default. This means as your application users adjust their text scaling preferences in the OS, your UI will reflect their choice. This produces a more accessible app by default.
Each control has an added FontAutoScalingEnabled
, and it even works with FontImageSource
for your font icons. Setting a FontSize
is your 100% size, and to lock it in you’ll set FontAutoScalingEnabled="false"
.
<VerticalStackLayout>
<Label
Text="Scaling disabled"
FontSize="18"
FontAutoScalingEnabled="False"/>
<Label
Text="Scaling enabled"
FontSize="18"/>
</VerticalStackLayout>
Be sure to review your screens and adjust styling as needed to make sure they are usable at all sizes.
Additional Highlights
Also in this release are several other notable additions.
- We have added support for
Effects
, which will support projects upgrading from Xamarin.Forms. #1574. - AppThemeBinding improvements for supporting dark and light theme modes #1657
- ScrollView handler #1669
- Android Shell ported to core #979
- Shell navigation passing complex objects #204
- Visual Tree Helper added for XAML Hot Reload #1845
- Switch to System.ComponentModel.TypeConverter #1725
- Window lifecycle events #1754
- Page navigation events #1812
- CSS prefix updated to
-maui
#1877
For a full set of changes, review the branch comparison.
Get Started Today
First thing’s first, install .NET 6 Preview 7. Next add the maui
workload using maui-check
. Also make sure you have updated to the latest preview of Visual Studio 2022.
In future versions of Visual Studio 2022 .NET MAUI will be installed alongside other workloads. For now
maui-check
from the CLI is our recommendation for installing everything you need.
Ready? Open Visual Studio 2022 Preview 3 and create a new project. Search for and select .NET MAUI.
For additional information about getting started with .NET MAUI, refer to our documentation.
Feedback Welcome
Visual Studio 2022 previews are rapidly enabling new features for .NET MAUI. As you encounter any issues with debugging, deploying, and editor related experiences, please use the Help > Send Feedback menu to report your experiences.
At the time of release, we are troubleshooting the latest Windows App SDK Single-project MSIX extension for Visual Studio 2022 and .NET MAUI to address a failure to debug. You can successfully deploy the Windows app directly and run it from the Start menu.
Please let us know about your experiences using .NET MAUI Preview 7 to create new applications by engaging with us on GitHub at dotnet/maui.
For a look at what is coming in future releases, visit our product roadmap, and for a status of feature completeness visit our status wiki.
69 comments
Very cool!
Lots of MAUI goodness. Great work!
Hi @David, interested to know about App (cold) startup time on Android for MAUI. For last couple of previews, it was almost same as Xamarin Forms GA. Does your team have any plans to significantly improve this before MAUI GA? Can we expect any numbers in percentage?
Xamarin forms are usable on Flagship phones but on mid-range Androids the Hello-World App take more than 10 seconds to start. Answer to this question is very important to us to understand clear picture. Thank you for the good work.
You can see some numbers here:
AOT just arrived for Android, and work started for profiled-AOT (Startup Tracing). There’s more work to be done there and with the linker to trim .NET MAUI apps. We have larger apps being profiled for those scenarios.
It’s good that this is now testable with published figures. It’s a bad start so I hope there is a lot of focus on improving on Forms significantly in startup time, overall perf, and (full AOT) deployment sizes, which should be an easy challenge since Forms is poor in all these areas.
Focusing on full AOT as we should:
– HelloForms is 382ms
– HelloMAUI is 502ms
It’s very concerning that in this thread people in the MAUI team are saying that Microsoft DI adds >100ms overhead and that “100ms for DI+Host we can live with”: https://github.com/dotnet/maui/issues/880#issuecomment-840648379 . To get startup times you need to be strict about every ms, not just accept an massive 100ms for a single feature!
It’s good to set a target for MAUI, e.g. 250ms for a simple app.
Full AOT also needs trimming support https://github.com/xamarin/xamarin-android/pull/6171#issuecomment-895573068 . 43MB without trimming. Trimming is a good test of .Net hygiene in that code that conforms to the type system will be easily trimmable.
Get this error when trying to run maui-check and I have updated to the latest .net core preivew:
Error: Error resolving type specified in JSON ‘DotNetCheck.Manifest.NuGetFeedVariableMapper, MauiCheck’. Path
‘check.variableMappers[0].$type’, line 9, position 74.
I got the same error too. first update the maui-chek tool.
dotnet tool update -g redth.net.maui.check
Thanks!
Thanks, safed me time to find the cause 🙂
Getting this error when trying to run maui-check
Fix failed – Workload Repair failed:
dotnet workload repair --source "https://api.nuget.org/v3/index.json" --source
"https://pkgs.dev.azure.com/dnceng/public/_packaging/6.0.100-preview.7.21379.14-shipping-1/nuget/v3/index.json" --source
"https://pkgs.dev.azure.com/azure-public/vside/_packaging/xamarin-impl/nuget/v3/index.json" --source
"https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json"
Try running
dotnet workload install maui
manually, I think that should work and thenmaui-check
to install the rest of the requirementsHi @Gerald
Manual installation fails. When running
I get the following:
Users of the maui-check tool seem to be the same error as I did here when running the dotnet workload command. If it’s of interest, you can see the isssue here: https://github.com/Redth/dotnet-maui-check/issues/105
I get the same. First I assumed my installation was broken, since I tried an RC1 build.
I need to find a way to clean-up my SDKs anyway.
Ok, a more specific error is:
Workload repair failed: The JSON value could not be converted to Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadPackId. Path: $.Id | LineNumber: 0 | BytePositionInLine: 25.
ok, I manually added missing stuff with dotnet workload install maui and dotnet workload install ios. And I successfully got vs 2022 to show the MAUI template. I created new MAUI project with the template, and successfully complied the 2 projects. Now I got a new issue that I cannot run the WinUI project even if it compiled successfully. The visual studio just say “unable to start debugging” “unable to run the project”. Is there anything I need to do to make WinUI work?
For the record. there is an exclamation mark on my dependency icon of .WinUI project. UniversalCRT.Debug, VCLibs, VCLibs.Desktop all have exclamation marks on them.
Yes, we need a VS fix to address the Windows issue. It’s in progress and we hope to be able to service that very soon. I mentioned a potential workaround at the end of the blog post you can try. Or wait for an update.
I know you guys are working hard and this is not a criticism at all, but just to let you know this is very painful for me and I can’t be the only one…
My ‘deployed’ app is crashing during the startup routine (doesn’t happen when running on mobile) but I obviously can’t attach the debugger until the app loads and for whatever reason my try catch block isn’t firing and so I can’t even capture the exception and put it in the logs.
Catch 22. I can’t move forward with the WinUI version. 😥
I have some context to add to this, that when trying to run the built WinUI assembly with the dotnet CLI, it will actually work and run, but it will crash at runtime saying that something with COM is not setup correctly and that a class needs to be registered, but was not. Below is the error text.
And below here is the code being referred to in the trace.
this comment has been deleted.
Hello! i have installed the visual studio 2022 preview 3 and everything looks good! The installation was successfull!
Now, I’m trying to install MAUI with this new version but i got an error 🙁
I Ran maui-check and i got everything OK, but when i try to install maui, i recieve the message:
…
Installing pack Microsoft.Maui.Controls.Runtime.win version 6.0.100-preview.7.1345…
Writing workload pack installation record for Microsoft.Maui.Controls.Runtime.win version 6.0.100-preview.7.1345…
Installing pack Microsoft.Maui.Essentials.Ref.win version 6.0.100-preview.7.1345…
Writing workload pack installation record for Microsoft.Maui.Essentials.Ref.win version 6.0.100-preview.7.1345…
Installing pack Microsoft.Maui.Essentials.Runtime.win version 6.0.100-preview.7.1345…
Writing workload pack installation record for Microsoft.Maui.Essentials.Runtime.win version 6.0.100-preview.7.1345…
Garbage collecting for SDK feature bands 6.0.100…
Workload installation failed: The JSON value could not be converted to Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadPackId. Path: $.Id | LineNumber: 0 | BytePositionInLine: 40.
Same here. In prev 6 i had issues for more than 2 weeks with installing single project extension (500 error) never fixed until prev 7 now maui workload installer is broken and i still cant test maui ugh…
There was a change in the manifest json a version or two back, so if you have previously installed .NET 6 and MAUI then this can happen. Remove other versions (typically in Program Files\dotnet), update maui-check to 0.7.3 or newer, and try again.
I’m not clear what needs removed.
With I run dotnet workload install maui with both the ..\sdk\6.0.100-preview.6.21355.2 and 7.21379.14 and folders and I get an error:
Updated advertising manifest microsoft.net.workload.mono.toolchain.
Garbage collecting for SDK feature bands 6.0.100…
Uninstalling workload pack version 6.0.100-preview.7.1063+sha.f5acc965e-azdo.5006556.
Workload installation failed: The JSON value could not be converted to Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadPackId. Path: $.Id | LineNumber: 0 | BytePositionInLine: 39.
If I delete the ..\sdk\6.0.100-preview.6.21355.2 folder I get it further down:
Installing workload manifest microsoft.net.sdk.tvos version 15.0.100-preview.7231.
Garbage collecting for SDK feature bands 6.0.100…
Workload installation failed: The JSON value could not be converted to Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadPackId. Path: $.Id | LineNumber: 0 | BytePositionInLine: 43.
If I try to remove anything from the ..\sdk-manifests\6.0.100 folder I get more errors.
I removed visual studio 2022 and all NET 6 components. I proceed to reinstall everything but i got a similar error:
Workload installation failed: The JSON value could not be converted to Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadPackId. Path: $.Id | LineNumber: 0 | BytePositionInLine: 39.
What worked for me is to remove everything under
C:\Program Files\dotnet\metadata\workloads
and then runmaui-check
ordotnet workload install maui
manuallyI did that and workload install finally worked but workload doesnt appear when creating new project…. I did maui-check then dotnet workload install maui everything green but cant create new maui projects
Edit made clean reinstall of vs and this time it worked. Unfortunetly the bug with debugging is too annoying to play around… Heres hoping rc1 will be finally fully useable on windows
Thanks for the advice! It worked for me too.
What worked for me was:
1.- Remove everything under
2.- Run the command
3.- Run the command
I created a project and everything worked good. I tested Android app and it looks wonderful!
Unfortunately i can’t test the windows project 🙁
Cannot start debugging. The startup project cannot be started. Make sure the correct project is set as the startup project. To change the startup project, you must select the command “Set as startup project” from the context menu of Solution Explorer.
Also, make sure that the debugging settings are correctly configured in the project properties.
The project is correctly marked as the Startup project but i’m not sure if i need to configure something else.
Any advices?
Thanks a lot!
@Luis Linares – David address your issue toward the bottom of the article:
“At the time of release, we are troubleshooting the latest Windows App SDK Single-project MSIX extension for Visual Studio 2022 and .NET MAUI to address a failure to debug. You can successfully deploy the Windows app directly and run it from the Start menu.”
Install the MSIX manually – then choose deploy on the windos.ui project and it’ll install to your start menu. From there you can run it and presumably attach the debugger.
the same error, nothing helps. It is time to use Darts!
Error: Error resolving type specified in JSON ‘DotNetCheck.Manifest.NuGetFeedVariableMapper, MauiCheck’. Path
‘check.variableMappers[0].$type’, line 9, position 74.
If this does not work try running https://github.com/Redth/dotnet-maui-check/blob/main/Clean-Old-DotNet6-Previews.ps1 before these steps.
After doing the tool uninstall I get this when I try to reinstall maui check
❯ dotnet tool install -g Redth.Net.Maui.Check
C:\Users\drhen\AppData\Local\Temp\grhhwwu0.qsp\restore.csproj(5,3): warning MSB4242: The SDK resolver “Microsoft.DotNet.MSBuildWorkloadSdkResolver” failed to run. Workload pack ‘Microsoft.NET.Runtime.Emscripten.Node’ in manifest ‘microsoft.net.workload.mono.toolchain’ [C:\Program Files\dotnet\sdk-manifests\6.0.100\microsoft.net.workload.mono.toolchain\WorkloadManifest.json] conflicts with manifest ‘microsoft.net.workload.emscripten’ [C:\Program Files\dotnet\sdk-manifests\6.0.100\microsoft.net.workload.emscripten\WorkloadManifest.json]
C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.ImportWorkloads.props(14,3): warning MSB4242: The SDK resolver “Microsoft.DotNet.MSBuildWorkloadSdkResolver” failed to run. Workload pack ‘Microsoft.NET.Runtime.Emscripten.Node’ in manifest ‘microsoft.net.workload.mono.toolchain’ [C:\Program Files\dotnet\sdk-manifests\6.0.100\microsoft.net.workload.mono.toolchain\WorkloadManifest.json] conflicts with manifest ‘microsoft.net.workload.emscripten’ [C:\Program Files\dotnet\sdk-manifests\6.0.100\microsoft.net.workload.emscripten\WorkloadManifest.json]
C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.ImportWorkloads.props(14,38): error MSB4236: The SDK ‘Microsoft.NET.SDK.WorkloadAutoImportPropsLocator’ specified could not be found. [C:\Users\drhen\AppData\Local\Temp\grhhwwu0.qsp\restore.csproj]
The tool package could not be restored.
Tool ‘redth.net.maui.check’ failed to install. This failure may have been caused by:
For more reasons, including package naming enforcement, visit https://aka.ms/failure-installing-tool
Hi @David, i wanted kow about the property MinimumHeightRequest what was its in Xamarin.Forms, the problem is what this property was bad interpreted for devs,
I thought that was property set one value minimum for heigth view case you heigth was smaller the value, but no is that. In MAUI this can exist?
Hi Diego, that work is planned. We’ll see if we will get to it in the next few sprints.
Developing with .NET MAUI not meant to be done on Linux?
Correct, we do not support Linux as a development environment for .NET MAUI.
It would be good knowing how many people would benefit from/need Linux environment support for development.
I do agree. And generally I’m sure that Microsoft will be able to find out the answer in case it feels like it needs to. However since .NET is “Free. Cross platform. Open source.” and also “Supported on Linux, Windows, and macOS” and MAUI is .NET, avoiding Linux support brings some dissonance. I was given tools (C#/F#, .NET), but I can’t use them. Not to mention that most popular cross platform UI frameworks do support Linux. So question arises.
Linux support is essential for teaching .NET MAUI and its adoption because many Software Engineering students and education institutions use Linux. Therefore, they usually prefer the technology available on all platforms.
this comment has been deleted.
I think the main competitor of Maui is flutter which supports Linux at a large stage. so I think support for Linux is crucial. Also, there should be extensions(hot reload and other stuff) to develop Maui from vs code properly.
The maui team should capitalize on the success of vs code and give proper support. Maui aim to be a great multi OS framework, like vs code is a great multi OS editor/ide. Only having first class experience on Windows is detrimental.
Plus, on the Mac, Visual Studio isn’t really usable. Its getting better, but still it requires more love ($+dev).
It’s the reason vs code is my editor of choice. Either I work on Windows, Mac (main) or Linux. It always work great.
When do you expect the debug issue to be fixed?
Is the error that I should be seeing when trying to debug: “The startup project cannot be launched. Ensure that the correct project is set as the startup project. The startup project can be changed by selecting the ‘Set as Startup Project’ command from the right click menu in Solution Explorer.”
It’s actively being worked on now, and once we have a fix we’ll jump on the next opportunity to ship it in a preview.