|
8 | 8 | using System.Diagnostics; |
9 | 9 | using System.IO; |
10 | 10 | using System.IO.Compression; |
| 11 | +using System.Linq; |
| 12 | +using System.Reflection; |
11 | 13 | using Microsoft.ML.Internal.Utilities; |
12 | 14 | using Microsoft.ML.Runtime; |
13 | 15 |
|
@@ -285,10 +287,10 @@ public static RepositoryWriter CreateNew(Stream stream, IExceptionContext ectx = |
285 | 287 | Contracts.CheckValueOrNull(ectx); |
286 | 288 | ectx.CheckValue(stream, nameof(stream)); |
287 | 289 | var rep = new RepositoryWriter(stream, ectx, useFileSystem); |
288 | | - var versionInfo = FileVersionInfo.GetVersionInfo(typeof(RepositoryWriter).Assembly.Location); |
| 290 | + |
289 | 291 | using (var ent = rep.CreateEntry(DirTrainingInfo, "Version.txt")) |
290 | 292 | using (var writer = Utils.OpenWriter(ent.Stream)) |
291 | | - writer.WriteLine(versionInfo.ProductVersion); |
| 293 | + writer.WriteLine(GetProductVersion()); |
292 | 294 | return rep; |
293 | 295 | } |
294 | 296 |
|
@@ -410,6 +412,24 @@ public void Commit() |
410 | 412 | Flush(); |
411 | 413 | Dispose(true); |
412 | 414 | } |
| 415 | + |
| 416 | + private static string GetProductVersion() |
| 417 | + { |
| 418 | + var assembly = typeof(RepositoryWriter).Assembly; |
| 419 | + |
| 420 | + var assemblyInternationalVersionAttribute = assembly.CustomAttributes.FirstOrDefault(a => |
| 421 | + a.AttributeType == typeof(AssemblyInformationalVersionAttribute)); |
| 422 | + |
| 423 | + if (assemblyInternationalVersionAttribute == null) |
| 424 | + { |
| 425 | + throw new ApplicationException($"Cannot determine product version from assembly {assembly.FullName}."); |
| 426 | + } |
| 427 | + |
| 428 | + return assemblyInternationalVersionAttribute.ConstructorArguments |
| 429 | + .First() |
| 430 | + .Value |
| 431 | + .ToString(); |
| 432 | + } |
413 | 433 | } |
414 | 434 |
|
415 | 435 | [BestFriend] |
|
0 commit comments