-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fixes #4505 Remove reliance on getting product version for model.zip/version.txt from FileVersionInfo and replace with using assembly custom attributes #4512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,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; | ||
|
||
|
@@ -305,10 +307,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; | ||
} | ||
|
||
|
@@ -432,6 +434,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}."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was only to keep consistency with how it was behaving before - I prefer the approach you have suggested though it should not fail because of this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please confirm @eerhardt @harishsk @yaeldekel and I'll make the change. |
||
} | ||
|
||
return assemblyInternationalVersionAttribute.ConstructorArguments | ||
.First() | ||
.Value | ||
.ToString(); | ||
} | ||
} | ||
|
||
[BestFriend] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Can this be renamed
assemblyInformationalVersionAttribute
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK sure