Skip to content

Commit 88a6b34

Browse files
authored
Merge pull request #848 from dotnet/fix828
Set application version properties for Maui projects
2 parents eac5c14 + 334b9dc commit 88a6b34

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

src/Nerdbank.GitVersioning.Tasks/build/Nerdbank.GitVersioning.targets

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,56 @@
219219
<RazorCompile Include="$(VersionSourceFile)" />
220220
</ItemGroup>
221221
</Target>
222+
223+
<!-- Support for Maui projects -->
224+
225+
<Target Name="NBGV_SetVersionForMauiAndroid"
226+
Condition="'$(TargetPlatformIdentifier)' == 'android'"
227+
BeforeTargets="_GetAndroidPackageName"
228+
DependsOnTargets="GetBuildVersion">
229+
<!-- Android requirement: ApplicationVersion must be a positive integer (used as an internal version number)
230+
To accommodate this, we do our best to fit the first three version components into a single integer that increases with each release.
231+
We'll bit-shift the major version to the most significant byte of a 4-byte integer.
232+
We'll bit-shift the minor version to the next most significant byte.
233+
We'll use the least 2 significant bytes for the build number.
234+
The major version must not exceed 124 to guarantee that the overall integer never exceeds 2100000000 even with the other numbers added.
235+
Other components are also limited since they must fit within the 8 or 16 bits allowed for them.
236+
Learn more from https://developer.android.com/studio/publish/versioning. -->
237+
<Error Condition="$([System.Version]::Parse('$(BuildVersion)').Major) &gt; 124" Text="Major version must not exceed 124 per Android versioning rules." />
238+
<Error Condition="$([System.Version]::Parse('$(BuildVersion)').Minor) &gt; 255" Text="Minor version must not exceed 256 per Android versioning rules." />
239+
<Error Condition="$(BuildNumber) &gt; 65535" Text="Build number must not exceed 65535 per Android versioning rules." />
240+
<PropertyGroup>
241+
<_NBGV_Major_Shifted>$([MSBuild]::Multiply($([System.Version]::Parse('$(BuildVersion)').Major), 16777216))</_NBGV_Major_Shifted>
242+
<_NBGV_Minor_Shifted>$([MSBuild]::Multiply($([System.Version]::Parse('$(BuildVersion)').Minor), 65536))</_NBGV_Minor_Shifted>
243+
244+
<ApplicationVersion>$([MSBuild]::Add($([MSBuild]::Add($(_NBGV_Major_Shifted), $(_NBGV_Minor_Shifted))), $(BuildNumber)))</ApplicationVersion>
245+
<ApplicationDisplayVersion>$(Version)</ApplicationDisplayVersion>
246+
</PropertyGroup>
247+
</Target>
248+
249+
<Target Name="NBGV_SetVersionForMauiIOS"
250+
Condition="'$(TargetPlatformIdentifier)' == 'ios' or '$(TargetPlatformIdentifier)' == 'maccatalyst'"
251+
BeforeTargets="_CompileAppManifest"
252+
DependsOnTargets="GetBuildVersion">
253+
<PropertyGroup>
254+
<!-- iOS requirement: ApplicationVersion must be a three part version number -->
255+
<ApplicationVersion>$(BuildVersionSimple)</ApplicationVersion>
256+
<!-- iOS requirement: ApplicationDisplayVersion must be a three part version number -->
257+
<ApplicationDisplayVersion>$(BuildVersionSimple)</ApplicationDisplayVersion>
258+
</PropertyGroup>
259+
</Target>
260+
261+
<Target Name="NBGV_SetVersionForMauiWindows"
262+
Condition="'$(TargetPlatformIdentifier)' == 'windows'"
263+
BeforeTargets="MauiGeneratePackageAppxManifest"
264+
DependsOnTargets="GetBuildVersion">
265+
<PropertyGroup>
266+
<!-- Windows requirement: ApplicationVersion must be blank when ApplicationDisplayVersion is a four part version number -->
267+
<ApplicationVersion></ApplicationVersion>
268+
<!-- Windows requirement: ApplicationDisplayVersion must be a four part version number -->
269+
<ApplicationDisplayVersion>$(BuildVersion)</ApplicationDisplayVersion>
270+
</PropertyGroup>
271+
</Target>
222272

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

0 commit comments

Comments
 (0)