.NET MAUI: Archive and Publish using Visual Studio Code
Tags: dotnet, dotnetmaui, vscode
Published: 2024-01-19 14:40:10

.NET MAUI (Multi-platform App UI) is a modern framework for building native cross-platform apps with C# and XAML. With .NET MAUI, you can target Android, iOS, macOS, and Windows platforms with a single codebase and a consistent user interface. In this post, I will show you how to use Visual Studio Code in **macOS**, a popular and lightweight code editor, to archive and publish your .NET MAUI apps with ease and efficiency.

---

### Recommendations
It is important to highlight that the official documentation from Microsoft is very helpful, and I encourage you to read it. Additionally, it is required for you to install the official .NET MAUI extension in Visual Studio Code.
- [Publishing using the command line for iOS](https://learn.microsoft.com/en-us/dotnet/maui/ios/deployment/publish-cli?view=net-maui-8.0)
- [Publishing using the command line for Android](https://learn.microsoft.com/en-us/dotnet/maui/android/deployment/publish-cli?view=net-maui-8.0)
- [.NET MAUI extension](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.dotnet-maui)

### How to archive and publish for iOS

1. Open your .NET MAUI app folder on Visual Studio Code. The .NET MAUI extension will automatically load your solution with the referenced projects.
2. Once Visual Studio Code loaded your project successfully, On the **Solution Explorer**, select the name of the project.
3. Open the Visual Studio Code integrated terminal and run the following command:
`dotnet publish -f net8.0-ios -p:ArchiveOnBuild=true`
4. The previous command will read your project properties you have set on your _.csproj_ file, for example:
```xml
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-ios|AnyCPU'">
	  <CreatePackage>false</CreatePackage>
	  <RuntimeIdentifier>ios-arm64</RuntimeIdentifier>
	  <CodesignProvision>Test App Distribution</CodesignProvision>
	  <CodesignKey>iPhone Distribution: Known (YYYYY123456)</CodesignKey>
	  <CodesignEntitlements>Platforms\iOS\Entitlements.plist</CodesignEntitlements>
	  <MtouchLink>SdkOnly</MtouchLink>
	  <MtouchUseLlvm>true</MtouchUseLlvm>
	</PropertyGroup>
```

> If your Apple Distribution Certificate and Apple Distribution Profile are valid, the output will be successfully.

- Once it finishes archiving and publishes the application, Launch XCode on macOS and then open the Organizer by going to the Window menu.
- On the Organizer window, select the app and version you want to validate and click the Validate button.
- If the application passes the validation, then click the Upload button and select your preferences, either for TestFlight only or TestFlight & Store.
- Done.

> Once the publishing process finishes on the terminal, what I love about the process above, is that I don't have to worry about the IPA location to upload it manually, and instead I use XCode to manage the upload for me. If you cannot use XCode, you can find the IPA file on the following folder path: _bin/Release/net8.0-ios/ios-arm64/publish/_ and upload it manually.

### How to archive and publish for Android

1. Open your .NET MAUI app folder on Visual Studio Code. The .NET MAUI extension will automatically load your solution with the referenced projects.
2. Once Visual Studio Code loaded your project successfully, On the **Solution Explorer**, select the name of the project.
3. Open the Visual Studio Code integrated terminal and run the following command:
`dotnet publish -f net8.0-android -p:ArchiveOnBuild=true`
4. The previous command will read your project properties you have set on your _.csproj_ file, for example:
```xml
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-android|AnyCPU'">
	  <AndroidKeyStore>True</AndroidKeyStore>
	  <AndroidSigningKeyStore>/Users/temp/projects/Certificates/testapp-keystore.jks</AndroidSigningKeyStore>
	  <AndroidSigningStorePass>123abc</AndroidSigningStorePass>
	  <AndroidSigningKeyAlias>testapp</AndroidSigningKeyAlias>
	  <AndroidSigningKeyPass>123def</AndroidSigningKeyPass>
	  <AndroidApkSignerAdditionalArguments>123abc</AndroidApkSignerAdditionalArguments>
	</PropertyGroup>
```
- If your keystore information is valid, the output will be successfully. So, the signed aab or apk can be uploaded to Google Play Console manually.

> You can find the signed **aab** or **apk** file on the following folder path: _bin/Release/net8.0-android/_ and upload it manually.

### Conclusion
With these skills, you can streamline your development workflow and deliver high-quality apps to your users. Honestly, I was scared at the beginning when Visual Studio for Mac was deprecated, but then when I saw the .NET MAUI extension in VS Code, I quickly shifted and started enjoying how fast it is to develop there.  

I hope you enjoyed this article and found it useful. If you have any questions or feedback, feel free to leave a comment below. 

Thank you for reading!

Follow me on Social:
- GitHub **[@vhugogarcia](https://github.com/vhugogarcia)**
- LinkedIn **[victorhugogarcia](https://www.linkedin.com/in/victorhugogarcia/)**
- Threads  **[@ihugo](https://www.threads.net/@ihugo)**
- X **[@ivictorhugo](https://twitter.com/ivictorhugo)**