Categories
.NET MAUI Extensions Templates Visual Studio Xamarin

.NET MAUI – Templates for Visual Studio 2022

.NET MAUI Project and Item templates for Visual Studio 2019 and 2022 with a VS extension package.

With .NET 6 Preview 6 released on Jul 14, 2021, and now Preview 7 released on Aug 10, 2021, .NET MAUI progressed a lot with Workloads, Gestures, Clipping, Alerts, New Layouts, and mainly first-class support for Visual Studio 2022 (with Preview 3.x). But, there is a catch in here. NO item templates for Visual Studio for now :-(.

Thankfully, VS extensions will always be there as a rescue in this sort of situation, and this time too. Have published an extension to the VS marketplace, for VS2022 users, that hosts the MAUI templates.

Update: Users on VS2019 don’t need to feel left out in this, I got you covered with another extension that hosts the Item templates for ContentPage and ContentView, in both XAML and C#, find it in the VS Marketplace – .NET MAUI Project and Item Templates.

This .NET MAUI Project and Item Templates extension can be downloaded from the VS Marketplace and then installed with VSIX installer or an easy way, install directly from within Visual Studio IDE itself (Extensions -> Manage Extensions or Alt+X+M shortcut). To find this extension, search with the maui keyword. Refer to the below screenshot.

Visual Studio Manage Extensions Dialog
Visual Studio – Manage Extensions (.NET MAUI in focus)

Note: To work with MAUI, installing .NET SDK, Visual Studio, and this extension alone is NOT enough. Since MAUI is an optional workload, it won’t get installed with Visual Studio for now. Maybe in a future version. For time being, this has to be manually installed with the below .NET CLI command in an elevated prompt.

dotnet workload install maui

Post-installation, verify whether it is getting listed as a .NET workload using dotnet workload list

.NET MAUI installed as optional workload
.NET MAUI installed as optional workload

And to run the WinUI project in VS2022, ensure this particular VS extension is installed, Single-project MSIX Packaging Tools for VS 2022

Coming back, this extension has a project template for both MAUI and MAUI Blazor app models and it has been named as:

  • .NET MAUI App (Preview 7)
  • .NET MAUI App (C#) (Preview 7)
  • .NET MAUI Blazor App (Preview 7)
  • .NET MAUI Class Library (Preview 7)
Visual Studio - Create Project - .NET MAUI templates
Visual Studio – Create Project – .NET MAUI Templates

And reg. Item templates:

ContentPage (both XAML and C#) and has been named as:

  • Content Page (.NET MAUI)
  • Content Page (C#) (.NET MAUI)

ContentView (both XAML and C#) and has been named as:

  • Content View (.NET MAUI)
  • Content View (C#) (.NET MAUI)

A page for defining app visual hierarchy with Shell and a page for managing resources with Resource Dictionary, both in XAML.

And now, this VS2022 extension is loaded with 25+ C# and XAML code snippets to improve the developer productivity as most of the snippets are backward compatible with Xamarin.Forms too. For the list of available snippets and their shortcuts with output format, take a look at this Getting Started guide. VS2019 extension will soon be enabled with these snippets.

Visual Studio - Add New Item dialog - MAUI Templates in focus
Visual Studio – Add New Item dialog – MAUI Templates in focus

Note: Currently, the project templates target .NET 6 Preview 7, and to support further changes in future .NET 6 releases, an update to this VS extension will be made available accordingly. ContentPage and ContentView will work with future versions as well, as not much change is expected over there.

For cross-platform users, a CLI-based .NET MAUI Templates is available to install from a NuGet package. And then can be invoked with dotnet new command. For more details, check out the GitHub repository.

Happy coding. Stay connected as we continue to learn and share the experiences from this exciting journey of being a software developer.

One reply on “.NET MAUI – Templates for Visual Studio 2022”

Comments are closed.