Skip to content

Commit

Permalink
Merge pull request #848 from dotnet/fix828
Browse files Browse the repository at this point in the history
Set application version properties for Maui projects
  • Loading branch information
AArnott committed Oct 22, 2022
2 parents eac5c14 + 334b9dc commit 88a6b34
Showing 1 changed file with 50 additions and 0 deletions.
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

0 comments on commit 88a6b34

Please sign in to comment.