文件版本信息和程序集信息

发布于 2024-10-08 04:40:22 字数 491 浏览 0 评论 0原文

鉴于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苦行僧 2024-10-15 04:40:22

我最初在此处找到了答案。为了便于参考,我重复了一些细节。

AssemblyInfo.cs 文件中可以包含三个“版本”:

[assembly: AssemblyVersion("1.1.1.1")]
[assembly: AssemblyInformationalVersion("2.2.2.2")]
[assembly: AssemblyFileVersion("3.3.3.3")]

如果未指定,AssemblyInformationalVersion 默认为 AssemblyFileVersion。同样,如果未指定,AssemblyInformationalVersion AssemblyFileVersion 默认为 AssemblyVersion

在您的示例中,AssemblyInfo.cs 文件不包含 AssemblyInformationalVersion,因此它默认为 AssemblyFileVersion 的值。正如您将在下面看到的,AssemblyInformationalVersion 映射到 FileVersionInfo.ProductVersion 属性,这解释了测试返回 true 的原因。

显然,这有几个令人沮丧的方面。首先,(据我所知)无法从 Visual Studio 设置 AssemblyInformationalVersion。您必须直接修改 AssemblyInfo.cs 文件以包含此属性。其次,AssemblyInformationalVersion 映射到 FileVersionInfo.ProductVersion 属性,这是不直观的。该属性更合适的名称应该是 AssemblyProductVersion。显然,标题也是描述等。

也就是说,我们如何在代码中检索这些(以及相关的)值?像这样:

AssemblyFileVersion =>;系统.诊断.FileVersionInfo.FileVersion
程序集信息版本 => System.Diagnostics.FileVersionInfo.ProductVersion
程序集版本 => System.Reflection.Assembly.Version

/// 其他的...
程序集标题 =>系统.诊断.FileVersionInfo.FileDescription
装配说明 => System.Diagnostics.FileVersionInfo.Comments
组装产品 => System.Diagnostics.FileVersionInfo.ProductName
装配公司 => System.Diagnostics.FileVersionInfo.CompanyName
装配版权=> System.Diagnostics.FileVersionInfo.LegalCopyright
组装商标 => System.Diagnostics.FileVersionInfo.LegalTrademarks

对于 AssemblyVersion,请使用:

string ver = Assembly.GetExecutingAssembly().GetName().Version.ToString();

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:

[assembly: AssemblyVersion("1.1.1.1")]
[assembly: AssemblyInformationalVersion("2.2.2.2")]
[assembly: AssemblyFileVersion("3.3.3.3")]

AssemblyInformationalVersion defaults to AssemblyFileVersion if it is not specified. Likewise, AssemblyInformationalVersion and AssemblyFileVersion default to AssemblyVersion if both are not specified.

In your example, the AssemblyInfo.cs file did not include AssemblyInformationalVersion, so it defaults to the value of AssemblyFileVersion. As you will see below, AssemblyInformationalVersion maps to the FileVersionInfo.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 the FileVersionInfo.ProductVersion property, which is non-intuitive. The attribute should more properly be named AssemblyProductVersion. And apparently, a title is also a description, etc.

That said, how do we retrieve these (and related) values in code? Like this:

AssemblyFileVersion          => System.Diagnostics.FileVersionInfo.FileVersion
AssemblyInformationalVersion => System.Diagnostics.FileVersionInfo.ProductVersion
AssemblyVersion              => System.Reflection.Assembly.Version

/// others...
AssemblyTitle                => System.Diagnostics.FileVersionInfo.FileDescription
AssemblyDescription          => System.Diagnostics.FileVersionInfo.Comments
AssemblyProduct              => System.Diagnostics.FileVersionInfo.ProductName
AssemblyCompany              => System.Diagnostics.FileVersionInfo.CompanyName
AssemblyCopyright            => System.Diagnostics.FileVersionInfo.LegalCopyright
AssemblyTrademark            => System.Diagnostics.FileVersionInfo.LegalTrademarks

In the case of AssemblyVersion, use this:

string ver = Assembly.GetExecutingAssembly().GetName().Version.ToString();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文