diff --git a/src/Microsoft.ML.Core/Data/Repository.cs b/src/Microsoft.ML.Core/Data/Repository.cs index 977e97a429..abbc26b88b 100644 --- a/src/Microsoft.ML.Core/Data/Repository.cs +++ b/src/Microsoft.ML.Core/Data/Repository.cs @@ -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; @@ -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; } @@ -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]