文件版本信息和程序集信息
鉴于 Blah.dll 的 AssemblyInfo.cs 中的这段代码:
[assembly: AssemblyVersion("3.3.3.3")]
[assembly: AssemblyFileVersion("2.2.2.2")]
然后在一个单独的 .exe 中:
var fileInfo = FileVersionInfo.GetVersionInfo("/path/to/Blah.dll");
fileInfo.ProductVersion == fileInfo.FileVersion == true;
其他 SO 问题显示 ProductVersion 是“正确的”,好奇我的使用方式是否有什么奇怪的地方。
ProductVersion 不应该是“3.3.3.3”而 FileVersion 不应该是“2.2.2.2”吗?什么会导致它将两个属性报告为 AssemblyFileVersion?
Given this snippet from Blah.dll's AssemblyInfo.cs:
[assembly: AssemblyVersion("3.3.3.3")]
[assembly: AssemblyFileVersion("2.2.2.2")]
And then in a separate .exe:
var fileInfo = FileVersionInfo.GetVersionInfo("/path/to/Blah.dll");
fileInfo.ProductVersion == fileInfo.FileVersion == true;
Other SO questions show ProductVersion being "correct", curious if there is something odd about how I'm using it.
Shouldn't ProductVersion be "3.3.3.3" and FileVersion be "2.2.2.2"? What would cause it to report both properties as AssemblyFileVersion?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最初在此处找到了答案。为了便于参考,我重复了一些细节。
AssemblyInfo.cs 文件中可以包含三个“版本”:
如果未指定,
AssemblyInformationalVersion
默认为AssemblyFileVersion
。同样,如果未指定,AssemblyInformationalVersion
和AssemblyFileVersion
默认为AssemblyVersion
。在您的示例中,AssemblyInfo.cs 文件不包含
AssemblyInformationalVersion
,因此它默认为AssemblyFileVersion
的值。正如您将在下面看到的,AssemblyInformationalVersion
映射到FileVersionInfo.ProductVersion
属性,这解释了测试返回 true 的原因。显然,这有几个令人沮丧的方面。首先,(据我所知)无法从 Visual Studio 设置
AssemblyInformationalVersion
。您必须直接修改 AssemblyInfo.cs 文件以包含此属性。其次,AssemblyInformationalVersion
映射到FileVersionInfo.ProductVersion
属性,这是不直观的。该属性更合适的名称应该是AssemblyProductVersion
。显然,标题也是描述等。也就是说,我们如何在代码中检索这些(以及相关的)值?像这样:
对于
AssemblyVersion
,请使用:I found the answer originally here. I'm repeating the details for ease of reference.
There are three 'versions' that can be included in the AssemblyInfo.cs file:
AssemblyInformationalVersion
defaults toAssemblyFileVersion
if it is not specified. Likewise,AssemblyInformationalVersion
andAssemblyFileVersion
default toAssemblyVersion
if both are not specified.In your example, the AssemblyInfo.cs file did not include
AssemblyInformationalVersion
, so it defaults to the value ofAssemblyFileVersion
. As you will see below,AssemblyInformationalVersion
maps to theFileVersionInfo.ProductVersion
property, which explains why the test returns true.Obviously, there are a couple of frustrating aspects to this. First, there is no way (that I know of) to set the
AssemblyInformationalVersion
from Visual Studio. You have to modify the AssemblyInfo.cs file directly to include this attribute. Second,AssemblyInformationalVersion
maps to theFileVersionInfo.ProductVersion
property, which is non-intuitive. The attribute should more properly be namedAssemblyProductVersion
. And apparently, a title is also a description, etc.That said, how do we retrieve these (and related) values in code? Like this:
In the case of
AssemblyVersion
, use this: