Using the latest .NET MAUI
Published: 2022-07-08 20:21:38

[.NET MAUI](https://dot.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](https://github.com/dotnet/maui/blob/main/.github/DEVELOPMENT.md) 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](https://github.com/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](https://github.com/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.

```console
$ git clone git@github.com:dotnet/maui.git
```

```console
$ git checkout net6.0
```

2. 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](https://github.com/dotnet/maui/blob/main/.github/DEVELOPMENT.md) 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.

```cli
$ dotnet tool restore
```

3. Run the cake script

Navigate to the maui folder and run the command:

```cli
$ dotnet cake --target=VS --pack
```

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
```

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](https://docs.github.com/en/github-cli). I installed it on my Mac using Brew.

```
$ brew install gh
```

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0hnoffoebbw1r4xr51r6.png)

```
$ gh pr checkout 8605
```

## Conclusion

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