Страница:
Migrating from Preview 7 to 8
Страницы
.NET 7 and .NET MAUI
Blazor Desktop
CLI iOS Simulator Selection
Capturing Binary Logs
Customizing Controls with Handlers
DeviceTests
FAQs
Guidelines for Customization of Controls
Handler Property PR Guidelines
Home
Installing .NET
Known Issues
Memory Leaks
Migrating Xamarin.Forms Effects
Migrating from Preview 10 to 11
Migrating from Preview 7 to 8
Migrating from Preview 8 to 9
Migrating from Preview 9 to 10
Migrating from Xamarin.Forms (Preview)
Migrating from Xamarin.Forms to .NET MAUI
Migrating to Preview 13
Migrating to Preview 14
Migrating to RC1
News
Nightly Builds
Porting Custom Renderers to Handlers
Profiling .NET MAUI Apps
Release Versions
Roadmap
Single Project
Status
Testing
UITests
Upgrading .NET MAUI from .NET 7 to .NET 8
Using Custom Renderers in .NET MAUI
Xamarin.Forms MAUI.Controls Layout Differences
Xamarin.Forms vs .NET MAUI
1
Migrating from Preview 7 to 8
David Ortinau редактировал(а) эту страницу 2021-09-14 11:20:20 -05:00
This document covers the main differences between previews that you'll need to adopt as you are updating projects from release to release.
Pre-Steps
- Uninstall all versions of .NET 6 previews via Add/Remove Programs
- Uninstall all versions of Visual Studio 2022
Minimum Requirements
- Visual Studio 2022 Preview 4 with .NET MAUI workload requirements (see installation docs)
- Android API 31 obtained via Android Studio
- OpenJDK 11
- Xcode 13 latest beta (Mac build host)
- Single Project extension for Windows App SDK
1 - Startup.cs to MauiProgram.cs
.NET MAUI now aligns with ASP.NET and Blazor with our usage of this host builder pattern.
- Rename Startup.cs to MauiProgram.cs
- Update the class and method to match the template
using Microsoft.Maui;
using Microsoft.Maui.Hosting;
using Microsoft.Maui.Controls.Compatibility;
using Microsoft.Maui.Controls.Hosting;
namespace MauiApp._1
{
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
});
return builder.Build();
}
}
}
- Update
Platforms/Android/MainApplication.cs
to implementCreateMauiApp()
and update the class inheritance. Do the same forPlatforms/iOS/AppDelegate.cs
, andPlatforms/MacCatalyst/AppDelegate.cs
.
using System;
using Android.App;
using Android.Runtime;
using Microsoft.Maui;
namespace MauiApp._1
{
[Application]
public class MainApplication : MauiApplication
{
public MainApplication(IntPtr handle, JniHandleOwnership ownership)
: base(handle, ownership)
{
}
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
}
2 - Windows Platform Single Project
The Windows platform is now part of the .NET MAUI single project.
- Use the template to add the base files to
Platforms/Windows
and update for your namespace. - Copy into
Platforms/Windows
and platform specific code you have in your Windows project. - Add any NuGet dependencies specific to Windows to the Single Project.
- Add launchSettings.json to the Properties folder.
- Remove your Windows project from the solution.
- Update your csproj file with the Windows TargetFramework and platform dependencies.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0-ios;net6.0-android;net6.0-maccatalyst</TargetFrameworks>
<!-- <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows')) and '$(MSBuildRuntimeType)' == 'Full'">$(TargetFrameworks);net6.0-windows10.0.19041</TargetFrameworks> -->
<OutputType>Exe</OutputType>
<RootNamespace>MauiApp._1</RootNamespace>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<EnablePreviewMsixTooling>true</EnablePreviewMsixTooling>
<!-- Display name -->
<ApplicationTitle>MauiApp.1</ApplicationTitle>
<!-- App Identifier -->
<ApplicationId>com.companyname.MauiApp._1</ApplicationId>
<!-- Versions -->
<ApplicationVersion>1.0</ApplicationVersion>
<AndroidVersionCode>1</AndroidVersionCode>
<!-- Required for C# Hot Reload -->
<UseInterpreter Condition="'$(Configuration)' == 'Debug'">True</UseInterpreter>
</PropertyGroup>
<ItemGroup>
<!-- App Icon -->
<MauiImage
Include="Resources\appicon.svg"
ForegroundFile="Resources\appiconfg.svg"
IsAppIcon="true"
Color="#512BD4" />
<!-- Splash Screen -->
<MauiSplashScreen Include="Resources\appiconfg.svg" Color="#512BD4" />
<!-- Images -->
<MauiImage Include="Resources\Images\*" />
<!-- Custom Fonts -->
<MauiFont Include="Resources\Fonts\*" />
</ItemGroup>
<ItemGroup Condition="$(TargetFramework.Contains('-windows'))">
<!-- Required - WinUI does not yet have buildTransitive for everything -->
<PackageReference Include="Microsoft.WindowsAppSDK" Version="WINDOWSAPPSDK_VERSION" />
<PackageReference Include="Microsoft.WindowsAppSDK.Foundation" Version="WINDOWSAPPSDK_VERSION" />
<PackageReference Include="Microsoft.WindowsAppSDK.WinUI" Version="WINDOWSAPPSDK_VERSION" />
<PackageReference Include="Microsoft.WindowsAppSDK.InteractiveExperiences" Version="WINDOWSAPPSDK_VERSION" NoWarn="NU1701" />
</ItemGroup>
<PropertyGroup Condition="$(TargetFramework.Contains('-windows'))">
<OutputType>WinExe</OutputType>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>
<PropertyGroup>
<!-- Required - WinUI can't deploy in a multi-targeting environment -->
<RuntimeIdentifier Condition="$(TargetFramework.Contains('-windows'))">win-x64</RuntimeIdentifier>
</PropertyGroup>
</Project>
3 - Update Android Theme
Android now uses the MaterialTheme which may conflict with older themes and styles. Update your MainActivity.cs
and/or styles.xml to be based on the @style/Maui.SplashTheme
Theme.
using Android.App;
using Android.Content.PM;
using Microsoft.Maui;
namespace MauiApp._1
{
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize)]
public class MainActivity : MauiAppCompatActivity
{
}
}
General Info
- How to Contribute
- Handler Property PR Guidelines
- Official Documentation
- Roadmap
- FAQs
- Nightly Builds
- Releases