Check version of Xamarin.Android programmatically

From the Xamarin Environment Testing Documentation , for iOS, I can check the version of Xamarin by contacting MonoTouch.Constants.Version.

Is there an equivalent for Xamarin.Android? I want to do this for logging.

+4
source share
1 answer

We did this with a file *.ttto read the version file of Xamarin.Android and generate a C # class containing version information:

<#@ template language="C#" #>
<#@ output extension=".cs" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Diagnostics" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Collections" #>
<#@ import namespace="System.Collections.Generic" #> 

namespace Versioning
{
    public class XamarinAndroid
    {
    <#

    #if __MonoCS__
        var path = @"/Library/Frameworks/Xamarin.Android.framework/Versions/Current";
    #else
        var path = (Directory.Exists(@"C:\Program Files (x86)"))
                ? @"C:\Program Files (x86)\MSBuild\Xamarin\Android"
                : @"C:\Program Files\MSBuild\Xamarin\Android";
    #endif
        string versionText = "unknown";
        if(Directory.Exists(path)) 
            versionText = File.ReadAllLines(Path.Combine(path, "Version"))[0];
    #>
        public const string Version = "<#=versionText#>";
    }
}

Custom Tool TextTemplatingFileGenerator. t4 , Xamarin.Android, .

+2

All Articles