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, .