-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Migrating from Preview 7 to 8
David Ortinau edited this page Sep 14, 2021
·
1 revision
This document covers the main differences between previews that you'll need to adopt as you are updating projects from release to release.
- Uninstall all versions of .NET 6 previews via Add/Remove Programs
- Uninstall all versions of Visual Studio 2022
- 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
.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();
}
}
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>
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
{
}
}