Skip to content

Commit

Permalink
Android: Update android manifest during build with generated assembly…
Browse files Browse the repository at this point in the history
… version.
  • Loading branch information
notsure2 committed Feb 11, 2018
1 parent fc14ae4 commit 5fcac21
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
20 changes: 20 additions & 0 deletions build/VersionXamarinAndroid.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project>
<Target Name="AddVersionToAndroidManifest" BeforeTargets="_GeneratePackageManagerJava">
<PropertyGroup>
<VersionInfoPath>$([System.IO.Path]::Combine($(MSBuildProjectDirectory), "Properties", "VersionInfo.cs"))</VersionInfoPath>
</PropertyGroup>

<PropertyGroup>
<Input Condition="Exists($(VersionInfoPath))">$([System.IO.File]::ReadAllText($(VersionInfoPath)))</Input>
<Pattern>\[assembly: AssemblyInformationalVersion[^"]+"([^"]+)"</Pattern>
<AndroidVersionName>$([System.Text.RegularExpressions.Regex]::Match($(Input), $(Pattern)).Groups[1].Value)</AndroidVersionName>
<Pattern>\[assembly: AssemblyVersion[^"]+"([^"]+)"</Pattern>
<ExtractedAssemblyVersion>$([System.Text.RegularExpressions.Regex]::Match($(Input), $(Pattern)).Groups[1].Value)</ExtractedAssemblyVersion>
<AndroidVersionCode>$(ExtractedAssemblyVersion.Substring($([MSBuild]::Add($(ExtractedAssemblyVersion.LastIndexOf('.')), 1))))</AndroidVersionCode>
<GeneratedManifestPath>$(IntermediateOutputPath)android\AndroidManifest.xml</GeneratedManifestPath>
</PropertyGroup>

<XmlPoke Condition="$(AndroidVersionCode) != ''" XmlInputPath="$(GeneratedManifestPath)" Namespaces="&lt;Namespace Prefix='android' Uri='http://schemas.android.com/apk/res/android' /&gt;" Query="manifest/@android:versionCode" Value="$(AndroidVersionCode)" />
<XmlPoke Condition="$(AndroidVersionName) != ''" XmlInputPath="$(GeneratedManifestPath)" Namespaces="&lt;Namespace Prefix='android' Uri='http://schemas.android.com/apk/res/android' /&gt;" Query="manifest/@android:versionName" Value="$(AndroidVersionName)" />
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,5 @@
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
<Import Project="..\..\build\Version.xml" />
<Import Project="..\..\build\WorkaroundXamarinAndroidBug1162.xml" />
<Import Project="..\..\build\VersionXamarinAndroid.xml" />
</Project>

0 comments on commit 5fcac21

Please sign in to comment.