Skip to content
Home » Basics of .NET MAUI – Part 24 – Deployment

Basics of .NET MAUI – Part 24 – Deployment

Spread the love

Our Slugrace app is ready to be published. Well, to be exact, it wouldn’t hurt to polish it a bit before, maybe run some tests to see if everything works and if there aren’t any dangerous bugs, but I’ll leave it as is. For our purposes, let’s say we’ve already made all the necessary corrections and our app is really ready for production.

As you know, we can deploy .NET MAUI apps to a lot of platforms. We decided to deploy our app to two platforms, Windows and Android. As we can only build for one platform at a time in Visual Studio, let’s build the app for Windows first and then for Android.

There are a couple different ways to publish an app for each platform. For Windows we’ll publish the app with Visual Studio to a folder, from which it can be installed on your machine. For Android we’ll publish the app for ad-hoc distribution so that it can be downloaded from a website or server.

So, let’s start with the Windows deployment.

Publishing for Windows to a Folder

We’re going to use Visual Studio to publish the app for Windows. We’ll package it into an MSIX package, which we can use to install the app on a machine.

First, let’s make sure the target platform is set to Windows Machine:

Right-click the project in the Solution Explorer and select Publish…:

In the Create App Packages window select Sideloading (A) and hit Next (B):

We need a certificate to publish the app. Select the second option (A) and hit Create (B): 

We’re going to create a temporary self-signed certificate that can be used for testing. We shouldn’t use it to distribute the package, though. For our purposes this will do.

Provide a company name and a password, then hit OK:

You will see a box with some information about the certificate. Hit OK:

You want to use this certificate, so check the Yes, us the current certificate option and hit Next:

You can leave the package version as is (A). By checking the Automatically increment box (B), you make sure the version will be incremented each time the package is published. In the Publishing profile drop-down select <New…> (C):

In the window that appears, set Configuration to Release | Any CPU and Target Runtime depending on which version of Windows you want to publish for. Then hit OK:

Now you can see the publishing profile in the drop-down. Hit the Next button:

In the next dialog enter the path to the folder in which you want to keep the installer (A). Also check one of the radio buttons to specify how often the app should look for updates (B). In our case, we’ll check for updates every time the app runs. Whenever a new version of the app is published, it will overwrite the old version. When done, hit the Create button (C):

Now the installer is being created. It may take some time. After that, you’ll see the following dialog with a package summary:

Hit the Copy and Close button to copy the package to the installer location you selected before.

The package is ready to be installed. Go to the folder where the installer was copied. In my case there’s the Slugrace_1.0.0.1_Test folder. It contains the MSIX file:

Let’s install the app. If you double-click the MSIX file, you’ll see the following dialog:

The Install button is disabled. This is because of the certificate. We first have to install the certificate. Close the dialog, right-click the MSIX file, select Properties and then the Digital Signatures tab. Select the certificate in the list and hit Details:

Hit View Certificate:

Then hit Install Certificate…:

Select Local Machine and hit Next:

Allow the changes on your device if you’re prompted to do so. In the next dialog check the Place all certificates in the following store radio button (A), click the Browse… button (B), select Trusted People from the list (C) and hit OK (D):

Hit Next and then Finish. You should see a message confirming that the import was successful. Click OK on each opened window.

If you now double-click the MSIX file, the Install button will be enabled:

Hit it to install the app.

Good. And now let’s publish the app for Android.

Publishing for Android for Ad-Hoc Distribution

With ad-hoc distribution we can make the app available for download from a website or server. So, let’s go back to Visual Studio and publish the app for Android.

For Android deployment we need the Android Package (APK) format. Right-click the project in the Solution Explorer and select Properties. Then, under Android, select Options (A) and make sure apk is selected in the Release drop-down (B):

As the debug target select your Android emulator (A) and select the Release configuration (B):

Right-click the project in Solution Explorer and select Publish… This will open the Archive Manager in a new tab. Visual Studio will start to archive the app bundle:

This may take a while. After that, make sure the archive is selected (A) and hit the Distribute… button (B):

In the Distribute – Select Channel dialog select Ad Hoc:

In the next dialog select the + button to create a new signing identity:

Next, the Create Android Keystore dialog opens. Enter an alias and a password. The alias should identify your key. You also have to provide at least some information below. It will be included in your certificate. Then hit the Create button:

Select the signing identity you just created (A) and hit the Save As button (B):

Select a location for your file and hit Save. When the Signing Password dialog shows up, enter the password you used before and hit the OK button:

Next, hit the Open Distribution button:

This will open the folder where the published app is. You can then distribute the app through a website or server.

Conclusion

This is it. We just created our first .NET MAUI app. I hope you enjoyed my series. Now we’re ready to create other beautiful apps for all the available platforms. .NET MAUI is a relatively new framework and it’s developing rapidly. You can build anything with it – the sky is the limit, so just go wild and show off your skills. See you in another series or on my Prospero Coder blog.


Spread the love

Leave a Reply