9

What's New in Xamarin and Visual Studio 2022 - Xamarin Blog

 2 years ago
source link: https://devblogs.microsoft.com/xamarin/whats-new-in-xamarin-and-visual-studio-2022/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

What’s New in Xamarin and Visual Studio 2022

David

November 8th, 2021

This week .NET Conf 2021 is celebrating the release of .NET 6, Visual Studio 2022 is now available, and we are happy to announce that Visual Studio 2022 also includes Xamarin support for Android 12, Apple’s latest Xcode 13 releases of iOS, iPadOS, macOS, and tvOS, and the latest Xamarin.Forms service releases that work with both. Let’s round up the latest Xamarin releases available today, revisit the Xamarin support policy, and look ahead at the road to .NET 6 and .NET MAUI coming in the second quarter of 2022.

.NET 6 is GA today and .NET Muti-platform App UI (MAUI) support is on the way for mobile and desktop! Today, continue building your production apps with Xamarin, check out the .NET MAUI previews as we work towards our release in Q2 2022, and when you’re ready try a migration of your projects with our .NET Upgrade Assistant.

Xamarin in Visual Studio 2022

Visual Studio 2022 introduces many improvements and new experiences, and Xamarin.Forms applications get these as well. The XAML Live Preview is one of the most exciting features that mirrors your running application within Visual Studio and enables adding layout guides and zooming to get your pixel perfect alignment. The Live Visual Tree allows you to see your UI hierarchy and locate the XAML source, and XAML Hot Reload continues to be improved as well.

Mobile and Cross-platform Sessions at .NET Conf 2021

Several sessions at .NET Conf have content for building mobile, desktop, and cross-platform applications with .NET today. Anything that mentions “.NET MAUI” is for you. Be sure to check out these sessions among others:

Session Speaker(s) Date Time (Pacific) .NET Conf Keynote Many Tuesday 11/9 8am Introduction to .NET MAUI Maddy Leger Montaquila Tuesday 11/9 10:30am Speed up your .NET Development with .NET Hot Reload Dmitry Lyalin Tuesday 11/9 11:30am Building cross-platform native apps with .NET MAUI and Blazor Eilon Lipton Tuesday 11/9 3:30am Drawn controls in .NET MAUI Javier Suarez Ruiz Thursday 11/11 2:00am Welcome to Maui Community Toolkit Pedro Jesus & Gerald Versluis Thursday 11/11 3:30am

Complete agenda

Xamarin ships support for the latest mobile versions

Over the past several months, Xamarin has shipped several service release for Xamarin.Forms, and .NET bindings for both beta and stable releases from Google and Apple. These SDKs are available in the new stable release of Visual Studio 2022 and servicing releases of Visual Studio 2019 (Xcode 13.1 SDKs support is shipping in the next service release for Visual Studio 2019).

  • Visual Studio 2022 (17.0) – download
  • Visual Studio 2022 for Mac (17.0) – download
  • Visual Studio 2019 (16.11.6) – download
  • Visual Studio 2019 for Mac (8.10.12) – download

Xamarin.Forms 5

Xamarin.Forms 5.0 service release 6 shipped October 18th, bringing 145 fixes since 5.0 initially shipped January 5th. This includes support for Android 12 and iOS 15, and we are on pace to continue shipping service releases approximately every 6 weeks. Need a release sooner? Remember, you can download builds from GitHub and Azure Pipelines from any pull request and commit. Full release notes are available. Update your applications today using your favorite NuGet package manager, and you’ll be in the best position for later upgrading to .NET MAUI.

Android 12

Google has shipped their latest stable version of Android 12 which includes an all new Material You design language modernization of Material Design, updated widget designs, overall system performance improvements, and new features and APIs for camera, graphics and images, media, security and privacy, storage, and more. For a complete list of updates and documentation, visit the Android developer portal.

To support Android 12 we’ve updated to OpenJDK 11 from version 8, and updated the Android designer, SDK manager, and device manager for compatibility.

iOS 15, iPadOS 15, tvOS 15

Apple has shipped Xcode 13 which includes iOS 15, iPadOS 15, and tvOS 15. Last week Apple also shipped Xcode 13.1 which added support for macOS Monterey 12.

Xamarin Support for 2 Years

With the change in schedule for shipping .NET MAUI and support for Android, iOS, and macOS in .NET 6, we want to update you on the support and servicing plan for Xamarin during this transition. Xamarin is governed by the Microsoft Modern Lifecycle which states that the current Xamarin release is supported for two years after the initial release, or until a newer, subsequent Current release. .NET MAUI and related platforms will be covered by the .NET and .NET Core Support Policy since, after all, it is a unified part of .NET now.

This means, from the last current release of Xamarin you’ll get two years of supported service releases. As was just highlighted above, Android and iOS shipped new releases so you can expect support through November 2023. This the timeframe you have to move existing projects to .NET 6, and we are working to make this a smooth process for you.

Preparing your transition to .NET 6

In the second quarter of 2022 we will ship a supported version of .NET Multi-platform App UI (MAUI), the next version of .NET support for cross-platform, mobile and desktop applications. A top priority for this transition is to make sure that Xamarin applications can upgrade to take advantage of the latest advancements in .NET, C#, and Visual Studio without rewrite. This means a Xamarin project need only be moved from .NET Framework to .NET 6 and you can continue shipping.

Let’s look first at what this means step-by-step for any Xamarin application.

Step 1: .NET Upgrade Assistant

The .NET Upgrade Assistant is a dotnet command-line tool that will perform the basic conversion of your project (csproj file) from the Xamarin .NET Framework style to the current SDK Style project that is commonly used by all other .NET project types. As you will recall, this transition unifies Xamarin with .NET so we share all the same tech and skills no matter what kind of apps we are building.

Step 2: Updating Dependencies

After converting the project file format, the tool will evaluate your project dependencies and report any incompatibilities for you to reevaluate. If you are using controls from a component vendor such as DevExpress, Infragistics, Steema, Syncfusion, Telerik, or others, they may already be available. Check with each for roadmap plans and availability.

The Xamarin Community Toolkit is shipping two options for upgrading to .NET 6. The first is a 1-to-1 compatible version of the toolkit that is compatible with .NET 6. The second option is a pure .NET 6 version that takes advantage of all the architectural improvements in .NET, though may not yet have 1-to-1 parity with the Xamarin Community Toolkit; check to see if what you need is available.

Xamarin.Essentials is now part of .NET 6 and .NET MAUI, so you will get that without any additional NuGet dependency.

If your project is Xamarin.Android or Xamarin.iOS, then you may well be done right here. Compile and test your application.

Step 3 (optional): Xamarin.Forms to .NET MAUI

.NET MAUI uses the same control naming, layout naming, navigation patterns, and XAML features that your applications use in Xamarin.Forms. This means it will all work as-is. So what has changed?

.NET MAUI uses the namespace “Microsoft.Maui” instead of “Xamarin.Forms”. The .NET Upgrade Assistant will have made this change for your in both your XAML and C# files. If you didn’t update NuGets that reference Xamarin.Forms types in the previous step with versions that now use Microsoft.Maui, then you’ll need to address those now.

What other differences will you encounter?

  1. App vs Window – Xamarin.Forms apps are single window, whereas .NET MAUI applications can be multi-window. This means the root view of the application has fundamentally been upgraded. We have preserved the style of App.cs (and App.xaml.cs) so your applications can continue to work as-is.

  2. Custom Renderers – .NET MAUI no longer needs them in the new “handler” architecture, however we provide a compatibility method for you to register them so you can continue to use them. For future needs, we recommend learning the handler pattern to customize platform control look and feel. For example, let’s say you have a custom renderer (CustomEntry in the library) for Android (CustomEntryRenderer in the Android project). To tell .NET MAUI where to find and how to use this renderer instead of the new handler, open the MauiProgram.cs in the root of your project where we have defined the app builder:

appBuilder
    .UseMauiApp<App>()
    .ConfigureMauiHandlers(handlers =>
    {
#if __ANDROID__
        handlers.AddCompatibilityRenderer(typeof(CustomEntry), typeof(Droid.Renderers.CustomEntryRenderer));
#endif
    });

That’s it. Do this for each renderer using the conditional compilation identifiers like __ANDROID__.

  1. Effects – just like with custom renderers, you can register effects in the app builder.
appBuilder
    .UseMauiApp<App>()
    .ConfigureEffects(effects =>
    {
        effects.Add<FocusRoutingEffect, FocusPlatformEffect>();
    });

Open your project in Visual Studio 2022 and start building. You may encounter a few type changes or incompatibilities. Resolve those and very soon you’ll have completed the transition to .NET 6.

You can expect this to be anywhere from a few hours to a few days of work, depending on the complexity of your application and the availability of .NET 6 compatible dependencies.

To attempt a migration today, please try out the .NET Upgrade Assistant and provide feedback so we can continue to improve the assistant between now and our GA release.

For additional examples of migrating projects from Xamarin.Forms to .NET MAUI, check out Javier Suarez Ruiz’s repository Xamarin.Forms to ,NET MAUI.

Starting Projects Today

.NET MAUI Preview 10 is available today in the Visual Studio 2022 preview channel, and Xamarin.Forms 5.0 is available. Both support the latest platform versions. If your project development timeline is longer than 4 months or everything you need is ready in .NET MAUI, then we recommend starting there. Otherwise, Xamarin.Forms is your best bet and you can see what lays ahead for you to transition to .NET 6 when you’re ready.

Get started today with these resources:

David Ortinau

Principal Program Manager, .NET Multi-platform App UI

Follow


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK