Gerald Versluis recently published these great videos on how to sign and publish your .NET MAUI Android app and .NET MAUI iOS app. In this blog post, I’ll be standing on his shoulders and show you how you can set up continuous integration (CI) in Azure DevOps for your .NET MAUI Android app using some of the steps provided in the video. This means that your .NET MAUI project will be built in Azure DevOps each time you push your code.
Create your pipeline
Start off by creating a new pipeline from Azure DevOps. Select the “Starter pipeline” and name your YAML file something like
android-maui-build.yml. We’ll modify this with the steps needed to create the AAB file (successor of APK) for your Android app.
Select your VM image
In your new YAML file, we need to modify which VM image we’ll be using. Since we want one that contains .NET 6, we’ll use
pool: vmImage: windows-2022
As of writing, the
windows-latest image has not yet been updated to use Visual Studio 2022 along with .NET 6, so we’ll have to explicitly set it to
Install the MAUI workload
Next, we’ll install the .NET MAUI workload onto the build agent. We need this to be able to build .NET MAUI apps. This can be done using the Command Line task and the
dotnet workload command:
- task: CmdLine@2 inputs: script: 'dotnet workload install maui'
If you’re planning on shipping your app to Google Play, you need to make sure you’ve signed your app package first. Gerald talks about how to do this in his video, so make sure you add those steps first. Once that’s done, add the .NET Core task to your pipeline and select the
build command. “Path to project” should point to your solution file containing the .NET MAUI project. In the “arguments” section we will specify that we will build with the Release configuration and that we should compile for the
- task: DotNetCoreCLI@2 inputs: command: 'build' projects: 'MyMAUIProject.sln' arguments: '-c Release -f net6.0-android'
And that should result in a signed AAB file!
If you want to use this file for a release pipeline, you need to publish it as a build artifact. To do this, first we need to copy our AAB file to the artifact staging directory. We’ll use the Copy files task for this:
- task: CopyFiles@2 inputs: SourceFolder: '$(agent.builddirectory)' Contents: '**/*-Signed.aab' TargetFolder: '$(build.artifactstagingdirectory)' flattenFolders: true
Finally, we’ll use the Publish build artifacts task to actually publish the file and make it available for a release pipeline:
- task: PublishBuildArtifacts@1 inputs: PathtoPublish: '$(Build.ArtifactStagingDirectory)' ArtifactName: 'drop' publishLocation: 'Container'
And there you go! You can combine this with a release pipeline for shipping this off to your testers via App Center or directly to the Google Play store if you want.
Here’s how the full YAML file would look like:
Being able to use
dotnet commands for .NET MAUI makes it very easy to set up your pipeline, especially compared to Xamarin. This also means that there’s much more transferrable knowledge if you’ve worked with pipelines for other apps that use .NET Core or above. I hope you found this useful and let me know if there are other aspects of this you would like to see!