Skip to content

Commit

Permalink
Fixes #4505 Remove reliance on getting product version for model.zip/…
Browse files Browse the repository at this point in the history
…version.txt from FileVersionInfo and replace with using assembly custom attributes (#4512)

Co-authored-by: Ross Eccleston <ross.eccleston@epicor.com>
  • Loading branch information
r0ss88 and r0ss88 committed Oct 12, 2021
1 parent 15eeef7 commit 9b28b24
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/Microsoft.ML.Core/Data/Repository.cs
Expand Up @@ -8,6 +8,8 @@
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using Microsoft.ML.Internal.Utilities;
using Microsoft.ML.Runtime;

Expand Down Expand Up @@ -285,10 +287,10 @@ public static RepositoryWriter CreateNew(Stream stream, IExceptionContext ectx =
Contracts.CheckValueOrNull(ectx);
ectx.CheckValue(stream, nameof(stream));
var rep = new RepositoryWriter(stream, ectx, useFileSystem);
var versionInfo = FileVersionInfo.GetVersionInfo(typeof(RepositoryWriter).Assembly.Location);

using (var ent = rep.CreateEntry(DirTrainingInfo, "Version.txt"))
using (var writer = Utils.OpenWriter(ent.Stream))
writer.WriteLine(versionInfo.ProductVersion);
writer.WriteLine(GetProductVersion());
return rep;
}

Expand Down Expand Up @@ -410,6 +412,24 @@ public void Commit()
Flush();
Dispose(true);
}

private static string GetProductVersion()
{
var assembly = typeof(RepositoryWriter).Assembly;

var assemblyInternationalVersionAttribute = assembly.CustomAttributes.FirstOrDefault(a =>
a.AttributeType == typeof(AssemblyInformationalVersionAttribute));

if (assemblyInternationalVersionAttribute == null)
{
throw new ApplicationException($"Cannot determine product version from assembly {assembly.FullName}.");
}

return assemblyInternationalVersionAttribute.ConstructorArguments
.First()
.Value
.ToString();
}
}

[BestFriend]
Expand Down

0 comments on commit 9b28b24

Please sign in to comment.