c# – AssemblyInformationalVersion属性行为改变:故意还是错误?

在使用VS2013构建的C#项目中,我可以将它放在AssemblyInfo.cs文件中:

[assembly: AssemblyInformationalVersion("7.1.0.0 Private (Debug build)")]

当我对另一个项目中的可执行文件使用FileVersionInfo.GetVersionInfo .NET API时,我发现这些值已报告:

>产品版本:7.1.0.0 Private(Debug build)
> ProductMajorPart:7
> ProductMinorPart:1

当我在使用VS2015构建的C#项目中使用相同的属性和字符串值时,ProductMajorPart和ProductMinorPart属性报告为零!

有谁知道行为改变是否是故意的?

我检查了可执行文件中找到的二进制文件版本信息,虽然版本信息中的字符串值与两个文件中的预期值一样,但VS2015可执行文件在VS_FIXEDFILEINFO.dwProductVersionMS和VS_FIXEDFILEINFO.dwProductVersionLS字段中的值为零.

最佳答案 我可以确认这种情况的行为变化,观察到如果AssemblyInformationalVersion是规范格式,例如“7.1.0.0”那么它在所有版本中都按预期工作,即产品版本major / minor / build / revision字段填写.

对于背景,docs for AssemblyInformationalVersion确实指定:

The attribute defined by this class attaches additional version information to an assembly. If this attribute is applied to an assembly, the string it specifies can be obtained at run time by using the Application.ProductVersion property.

[…] Although you can specify any text, a warning message appears on compilation if the string is not in the format used by the assembly version number […]

从上面:

>除了可以检索字符串本身之外,没有正式的保证;
>警告不要使用自由格式字符串.

您可能,甚至应该在VS connect上提交错误报告,尽管我的感觉是MS将AssemblyInformationalVersion中的自由格式字符串视为不受支持的“意外”功能,并且可能不会将未记录的行为更改视为“错误” .

没有直接相关,但是这个VS 2010错误报告Localized build with free form AssemblyInformationalVersion causes ALINK warning AL1053已被MS关闭,因为无法修复.

在Why is warning CS1607 “The version specified for the ‘product version’ is not in the normal ‘major.minor.build.revision’ format” generated?接受的答案基本上建议一旦你偏离标准的major.minor.build.revision格式,你几乎就是你自己.

点赞