IDecompilationService - Use Assembly.GetName().Version rather than FileVersionInfo.GetVersionInfo#82490
IDecompilationService - Use Assembly.GetName().Version rather than FileVersionInfo.GetVersionInfo#82490MattParkerDev wants to merge 2 commits intodotnet:mainfrom
Conversation
|
Does ILSpy guarantee that the assembly version and file version will be roughly the same? I imagine we did this because some assemblies tend to put fairly meaningless stuff in the assembly version (since changing assembly version can cause issues), and the file version is where "interesting" version information is. |
This just seems to be informational to let the user what version of ilspy was used for decompilation. I am not sure how exact we need to be. I suppose we could make this a fallback for when the assembly does not exist on disk with little consequence. |
|
@JoeRobich yep, it's informational. As long as assembly version is "informational enough" then we're good. But some projects take the philosophy that the assembly version is basically frozen for all time, since changing it breaks stuff. In that case, it's not so informational anymore. |
|
@jasonmalinowski So it appears that ilspy disables generation of the FileAssembly Version and only sets the AssemblyVersion. Meaning the AssemblyVersion will be used for both. |
Then that's good enough for me if we just put a comment to that effect in this PR that we're going to keep assuming it. |
Done! Feel free to alter the wording of the comment. |
| private static readonly FileVersionInfo s_decompilerVersion = FileVersionInfo.GetVersionInfo(typeof(CSharpDecompiler).Assembly.Location); | ||
| // ICsharpCode.Decompiler disables generation of the AssemblyFileVersion, and sets the AssemblyVersion, meaning that | ||
| // typeof(CSharpDecompiler).Assembly.GetName().Version and FileVersionInfo.GetVersionInfo(typeof(CSharpDecompiler).Assembly.Location) return the same version. | ||
| private static readonly Version s_decompilerVersion = typeof(CSharpDecompiler).Assembly.GetName().Version ?? throw new ArgumentNullException(); |
There was a problem hiding this comment.
I'd say change this to a string and then substitute out "unknown" in the case of a failure; otherwise if this were to fail then decompilation would be entirely busted. Not worth it for some debugging string.
FileVersionInfo.GetVersionInfo requires a path to an assembly on disk. This fails in cases where the assembly has been loaded as a stream, rather than from a file.
This replaces it with Assembly.GetName().Version, which I have verified returns the same string, in this case, for ICSharpCode.Decompiler - "9.1.0.7988".
This will also improve performance (probably unnoticeably), as it doesn't need to read the assembly details from disk.