Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

AssemblyInfo

Samantha Houts edited this page Jul 18, 2019 · 4 revisions

Get information about Xamarin.Forms version, package version, build and associated commit:

As of Xamarin.Forms 4.0, all assemblies inside the public nupkg provide information about the package version they reference, the corresponding GitHub commit, and the AzureDevOps build ID that created the package.

We use Version.targets and GitInfo to get the git commit information, and we use MSBuilder.GenerateAssemblyInfo to add this metadata to non-SDK style projects.

You can retrieve this information from the AssemblyFileVersion or, for more detailed info, the AssemblyInformationalVersion metadata.

AssemblyInformationalVersion provides something like {XamarinFormsVersionWithSuffix}+sha.{commit}-azdo.{buildid}.

Some example code to extract the values:

   var xamarinFormsAssembly = Assembly.Load($"Xamarin.Forms.Core");
   var fileVersion = (AssemblyFileVersionAttribute)Attribute.GetCustomAttribute(xamarinFormsAssembly, typeof(AssemblyFileVersionAttribute), false);
   var informationalVersion = (AssemblyInformationalVersionAttribute)Attribute.GetCustomAttribute(xamarinFormsAssembly, typeof(AssemblyInformationalVersionAttribute), false);

    var info = informationalVersion.InformationalVersion.Split('+');

    if (info.Length > 1)
    {
         PackageVersion = info[0];
         var infos = info[1].Split('-');
         foreach (var item in infos)
         {
            if (item.Contains("azdo."))
            {
               BuildId = item.Replace("azdo.", "");
               AzdoUrl = $"https://dev.azure.com/devdiv/DevDiv/_build/results?buildId={BuildId}";
            }
            if (item.Contains("sha."))
            {
               Sha = item.Replace("sha.", "");
               ShaUrl = $"https://github.com/xamarin/Xamarin.Forms/commits/{Sha}";
            }
          }
    }

Sample code

Visit this sample

Run the sample and visit the AboutPage

alt text alt text alt text