Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set application version properties for Maui projects #848

Merged
merged 1 commit into from
Oct 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,56 @@
<RazorCompile Include="$(VersionSourceFile)" />
</ItemGroup>
</Target>

<!-- Support for Maui projects -->

<Target Name="NBGV_SetVersionForMauiAndroid"
Condition="'$(TargetPlatformIdentifier)' == 'android'"
BeforeTargets="_GetAndroidPackageName"
DependsOnTargets="GetBuildVersion">
<!-- Android requirement: ApplicationVersion must be a positive integer (used as an internal version number)
To accommodate this, we do our best to fit the first three version components into a single integer that increases with each release.
We'll bit-shift the major version to the most significant byte of a 4-byte integer.
We'll bit-shift the minor version to the next most significant byte.
We'll use the least 2 significant bytes for the build number.
The major version must not exceed 124 to guarantee that the overall integer never exceeds 2100000000 even with the other numbers added.
Other components are also limited since they must fit within the 8 or 16 bits allowed for them.
Learn more from https://developer.android.com/studio/publish/versioning. -->
<Error Condition="$([System.Version]::Parse('$(BuildVersion)').Major) &gt; 124" Text="Major version must not exceed 124 per Android versioning rules." />
<Error Condition="$([System.Version]::Parse('$(BuildVersion)').Minor) &gt; 255" Text="Minor version must not exceed 256 per Android versioning rules." />
<Error Condition="$(BuildNumber) &gt; 65535" Text="Build number must not exceed 65535 per Android versioning rules." />
<PropertyGroup>
<_NBGV_Major_Shifted>$([MSBuild]::Multiply($([System.Version]::Parse('$(BuildVersion)').Major), 16777216))</_NBGV_Major_Shifted>
<_NBGV_Minor_Shifted>$([MSBuild]::Multiply($([System.Version]::Parse('$(BuildVersion)').Minor), 65536))</_NBGV_Minor_Shifted>

<ApplicationVersion>$([MSBuild]::Add($([MSBuild]::Add($(_NBGV_Major_Shifted), $(_NBGV_Minor_Shifted))), $(BuildNumber)))</ApplicationVersion>
<ApplicationDisplayVersion>$(Version)</ApplicationDisplayVersion>
</PropertyGroup>
</Target>

<Target Name="NBGV_SetVersionForMauiIOS"
Condition="'$(TargetPlatformIdentifier)' == 'ios' or '$(TargetPlatformIdentifier)' == 'maccatalyst'"
BeforeTargets="_CompileAppManifest"
DependsOnTargets="GetBuildVersion">
<PropertyGroup>
<!-- iOS requirement: ApplicationVersion must be a three part version number -->
<ApplicationVersion>$(BuildVersionSimple)</ApplicationVersion>
<!-- iOS requirement: ApplicationDisplayVersion must be a three part version number -->
<ApplicationDisplayVersion>$(BuildVersionSimple)</ApplicationDisplayVersion>
</PropertyGroup>
</Target>

<Target Name="NBGV_SetVersionForMauiWindows"
Condition="'$(TargetPlatformIdentifier)' == 'windows'"
BeforeTargets="MauiGeneratePackageAppxManifest"
DependsOnTargets="GetBuildVersion">
<PropertyGroup>
<!-- Windows requirement: ApplicationVersion must be blank when ApplicationDisplayVersion is a four part version number -->
<ApplicationVersion></ApplicationVersion>
<!-- Windows requirement: ApplicationDisplayVersion must be a four part version number -->
<ApplicationDisplayVersion>$(BuildVersion)</ApplicationDisplayVersion>
</PropertyGroup>
</Target>

<!-- Workaround till https://github.com/NuGet/NuGet.Client/issues/1064 is merged and used. -->
<Target Name="_NBGV_CalculateNuSpecVersionHelper"
Expand Down