DEV Community

David Ortinau
David Ortinau

Posted on

Using the latest .NET MAUI

.NET MAUI has been GA for all of 46 days, and we are already craving new releases; especially bug fixes. Since .NET MAUI ships as an optional workload of .NET itself, you cannot simply download a NuGet package to your local system and reference that.

You might think there would be a nightly feed to obtain .NET MAUI releases, or to be able to download artifacts directly from GitHub.com. That's not the case, but the answer is almost as simple.

I have been using the dotnet workload install maui command as specified in the contributor development guide at dotnet/maui. This along has worked well until...it didn't. I found I often installed and uninstalled myself into a mess.

Let's look at how you can easily use the very latest commits to dotnet/maui in your local development.

A Better Option

Here's what I've been doing for a few days now at the advice of Shane Neuville from the .NET MAUI engineering team, and it has been working really well. This is very close to what is written in the development guide for contributors today, but I thought distilling it here might be helpful.

  1. Clone dotnet/maui and checkout the branch I want to use.

In most cases this will be net6.0 for me, since main branch is now .NET 7 and I'm not quite ready for that yet.

$ git clone git@github.com:dotnet/maui.git
Enter fullscreen mode Exit fullscreen mode
$ git checkout net6.0
Enter fullscreen mode Exit fullscreen mode
  1. Restore dotnet tools.

Prerequisite: make sure you're on the correct version of .NET. At the time of this writing I'm using 6.0.400-preview.22330.6. The development guide for dotnet/maui may provide details on the version alignment if you need pointers.

You need cake so you can run the scripts to build and pack the workload artifacts.

$ dotnet tool restore
Enter fullscreen mode Exit fullscreen mode
  1. Run the cake script

Navigate to the maui folder and run the command:

$ dotnet cake --target=VS --pack
Enter fullscreen mode Exit fullscreen mode

Upon completion you should see a report such as:

Task                          Duration
--------------------------------------------------
Clean                         Skipped
dotnet                        00:00:02.1838200
dotnet-buildtasks             00:00:49.1258432
dotnet-pack-maui              00:00:25.5596615
dotnet-pack-additional        00:00:12.1436858
dotnet-pack-library-packs     00:00:11.1900158
dotnet-pack-docs              00:00:05.8721475
VS                            00:00:00.3401180
--------------------------------------------------
Total:                        00:01:46.4153762
Enter fullscreen mode Exit fullscreen mode

The newly generated packages are now in the maui source folder and environment variables have been configured so that Visual Studio will now use and prefer those workloads. Look at the script output for specific locations.

Visual Studio should open once the script succeeds, and now any .NET MAUI project you open will use the newly generated package from source.

As usual, clean and delete the bin/obj folders of your solution if you ever doubt that you have the latest code. Also, a close and reopen Visual Studio between rebuilds of .NET MAUI source is probably wise to make sure your solution grabs and restores the latest packages.

Testing PRs

I was recently testing a fix from a pull request (PR), and this method made that super easy. First, I checked out the PR locally just like a branch. I then did the build step above and tested my app as usual.

To checkout a PR, I found it easiest to use the GitHub CLI. I installed it on my Mac using Brew.

$ brew install gh
Enter fullscreen mode Exit fullscreen mode

And then from GitHub.com I just copied the CLI command to checkout the PR locally.

Image description

$ gh pr checkout 8605
Enter fullscreen mode Exit fullscreen mode

Conclusion

That's it. What tips do you have to help developers and contributors be successful with .NET MAUI?

Top comments (2)

Collapse
 
ali50m profile image
ali50m • Edited

Hi David, I am willing to try MAUI. However, I am highly dependent on the VS/reshaper work environments. Could you kindly let know if I need to switch the current official VS community version to a preview version which could not work well with resharper? I just do not want to mess my work environment. But if there is a chance, I would like to try the MAUI out. Thanks!

Collapse
 
davidortinau profile image
David Ortinau

You would need to use the preview version of VS today. Very soon .NET MAUI will be in the GA release of VS. You can also install the preview side-by-side with your current version on Windows.