How to change application display version in .NET MAUI
MAUI provides us the way to change application display and build version:
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<ApplicationVersion>1</ApplicationVersion>
However, if we change the value of ApplicationDisplayVersion, MAUI will raise multiple errors when you run it.
After researching, i found a workaround to do it instead, by setting specific version for each platform.
On Android: we just double click on AndroidManifest.XML in Android folder and then set your app version and app name:
On iOS: double click on Info.plist in iOS folder.
In order to get app version in code-behind. you can refer to this invoke-platform-code to get version for each platform.
You can follow my code below:
- Step 1: Create an Interface named IDevicePlatformService having GetVersionName method.
- Step 2: In Android and iOS folder, create 2 classes having the same name is DevicePlatformService, both of them inherite from IDevicePlatformService.
- Step 3: Add the following code for each platform:
Android:
iOS:
- Step 4: Register dependencies in MauiProgram.cs
After doing all these steps, you can get app version in your code-behind.
Hope this helpful for some of you.