问题描述
今天,我得到了'产品版本指定的的版本是不正常的major.minor.build.revision'格式的警告。
Today I'm getting a The version specified for the 'product version' is not in the normal 'major.minor.build.revision' format warning.
它与使用的
It's related to the use of AssemblyInformationalVersionAttribute
.
我组装的属性有:
[assembly: AssemblyInformationalVersion("XXX 1.1.0")]
[assembly: System.Runtime.InteropServices.ComVisible(false)]
基本上,编译器会抱怨 XXX 1.1.0
并不像 xyzr
。从MSDN:
Basically the compiler complains about XXX 1.1.0
that doesn't look like x.y.z.r
. From MSDN:
该信息的版本为
装配其他版本信息,字符串格式。这是仅供参考
并在运行时不被使用。虽然可以指定任何文本,如果该字符串不是由程序集版本号使用的
格式上编译出现
警告信息,或者如果它是在格式
,但包含通配符字符。该警告是无害的。
所以他们说的警告是的无害的可能发生。问题是,它打破我的体型。我甚至无法抑制CS1607警告(我想,在项目级,无效果)的建议在以下错误的
So they say a warning that is harmless can occur. The problem is, it breaks my build. I can't even suppress the CS1607 warning (I tried that at the project level, no effect) as suggested in the following bug http://connect.microsoft.com/VisualStudio/feedback/details/275197/assemblyinformationalversion-should-not-generate-cs1607
其实,一切都很好(没有警告),直到我添加本地化资源到我的项目。我以前曾在项目中的 MyResources.resx
文件。我添加了一个本地化的 MyResources.fr.resx
文件,这个资源是警告的来源(或至少是:如果我从项目中删除此文件,它没有编译警告)。
Actually, everything was fine (no warning) until I added localized resources to my project. I previously had a MyResources.resx
file in the project. I added a localized MyResources.fr.resx
file, and this resource is the source of the warning (or at least: if I remove this file from the project, it compiles without warning).
我没有看到()CS1607之间的链接关系到64 VS 86, AssemblyInformationalVersionAttribute
和本地化的资源文件...
I don't see any link between CS1607 (related to x64 vs x86), AssemblyInformationalVersionAttribute
and a localized resource file...
我怎么能修复我的项目,所以我可以使用 XXX 1.1.0
作为 AssemblyInformationalVersionAttribute
没有任何(即使是无害的)警告?
How could I fix my project so I can use XXX 1.1.0
as AssemblyInformationalVersionAttribute
without any (even harmless) warning?
我不与抑制CS1607警告OK(即可能是错误引用的情况下)是有用的,但我甚至没有成功地压制了它。
I'm not that OK with suppressing the CS1607 warning (that could be useful in case of wrong references), but I didn't even managed to suppress it.
不要注意我发现这是CS1607由谷歌搜索时,编译器再也没有回来实际的警告代码。
Do note I found it was CS1607 by googling, the compiler never returned the actual warning code.
另外请注意我的项目面向.NET 2.0,并移动到.NET 4.0修复该问题(当然我不能这样做)。
Also note my project targets .Net 2.0, and moving to .Net 4.0 fixes the issue (but of course I can't do this).
任何解释,是值得欢迎的。
Any explanation is welcome.
PS:
的正常major.minor.build.revision'格式的问题是没有关系(不是关于 AssemblyInformationalVersion
)
PS:The version specified for the 'file version' is not in the normal 'major.minor.build.revision' format in .NET is question is not related (not about AssemblyInformationalVersion
)
编辑:
感谢汉斯帕桑特。从你的答案,我理解 AssemblyInformationalVersion
用于生成在Win32 的ProductVersion 可用值> VERSIONINFO 结构。
Thanks Hans Passant. From your answer, I understand AssemblyInformationalVersion
is used to generate the two ProductVersion
values available in the Win32 VersionInfo
structure.
- 如果在
AssemblyInformationalVersion
属性为空,则的AssemblyVersion
代替。 - 如果
AssemblyInformationalVersion
是XYZ
,无论的ProductVersion
值XYZ
。 - 如果
AssemblyInformationalVersion
是另一个字符串的的ProductVersion
未设定数值(0.0.0
),只有文本的ProductVersion
值设置。
- If the
AssemblyInformationalVersion
attributes is empty, thenAssemblyVersion
is used instead. - If
AssemblyInformationalVersion
isx.y.z
, bothProductVersion
values arex.y.z
. - If
AssemblyInformationalVersion
is another string, the number value ofProductVersion
is not set (0.0.0
) and only the textualProductVersion
value is set.
我不明白,是的为什么的的CS1607警告只有在某些特定的情况下,编译器生成:在我的情况下,只有当项目包含本地化RESX文件和面向.NET 2.0
What I do not understand, is why the CS1607 warning is only generated by the compiler under some specific circumstances: in my case only when the project contains localized resx files and targets .Net 2.0.
我用 AssemblyInformationalVersion
字符串多年没有任何警告,直到昨天,当我增加了一个本地化的resx到项目中。
I used a string in AssemblyInformationalVersion
for years without any warning until yesterday, when I added a localized resx to the project.
我行与不具有数的ProductVersion
设置值(如你所说,只有文字和人类可读的值是对我很重要),但有一个方法,以防止该警告长大的吗?
I'm OK with not having the number ProductVersion
value set (as you said, only the textual and human-readable value is important for me), but is there a way to prevent the warning from being raised?
编辑2:
我已经创建了一个演示问题非常小的溶液样品:的
I've created a very small solution sample that demonstrates the issue: http://sharesend.com/mb371c3l
- 首先编译:预期CS1607编译器提出
- 然后取出
Logon.aspx.fr.resx
和重建所有:我的机器上没有更多的警告,原因未知。
- First compilation: expected CS1607 raised by the compiler.
- Then remove
Logon.aspx.fr.resx
and rebuild all: no more warning on my machine, for an unknown reason.
推荐答案
C#编译器不适用的untrivial转换到这些属性。它需要生成的非托管的资源,为可执行文件。必要的,因为Windows不知道管理的资源或属性的东西。这通常是自动地完成的。像 [AssemblyInformationalAttribute]
会自动转换生成版本资源的产品版本号。不过,别注意激烈的命名不匹配,而不是一个错误。
The C# compiler does apply an untrivial conversion to these attributes. It needs to generate the unmanaged resources for the executable. Necessary because Windows doesn't know anything about managed resources or attributes. This is normally done automagically. Like the [AssemblyInformationalAttribute]
is auto-converted to generate the Version resource's Product version number. Do note the drastic naming mismatch, not a mistake.
非托管产品版本是相当麻烦的。有些事情,你看到后面的FileVersionInfo类,就是那个让你从一个可执行文件读回的非托管版本资源。注意它的ProductVersion属性如何返回的字符串的。但ProductMajorPart(和未成年人,建立和私有)财产返回的 INT 的
The unmanaged product version is however pretty troublesome. Something you see back in the FileVersionInfo class, the one that lets you read back the unmanaged version resource from an executable file. Note how its ProductVersion property returns a string. But the ProductMajorPart (and minor, build and private) property return an int.
您可能已经看到了摩擦。对于久违的在时间的迷雾一些深不可测的原因,版本资源的原始规格包括产品版本的两次的。一旦为二进制数,再作为一个字符串。该字符串可以本地化,对于这种重复的可能原因。你也可以看到这回,当你在与非托管资源编辑器中的资源。使用文件+打开+文件,并选择可执行文件。双击Version.1资源。你会看到产品版本在此对话框中出现两次为好。顶一个只接受数字,一个底部接受任何字符串。
You probably see the friction by now. For some unfathomable reason long lost in the fog of time, the original spec of the Version resource included the Product version twice. Once as a binary number, again as a string. The string can be localized, the probable reason for this duplication. You can also see this back when you look at the resource with the unmanaged resource editor. Use File + Open + File and select the executable file. Double click the Version.1 resource. You'll see the Product version appear twice in this dialog as well. The top one only accepts numbers, the bottom one accepts any string.
这离开C#编译器了小溪没有桨,它的必须属性字符串转换为整数,因此它可以生成二进制数为好。显然,不能只让那个出问题没有至少产生一个警告。在MSDN文档为CS1607的说法,这是良性并不十分准确,你真的结束了不具备二进制产品版本集的资源。这最终导致故障的几率是不是然而,伟大的,其他程序通常不读回,它往往只在人类来看待。 详细信息属性表在资源管理器的属性对话框的文件显示。该字符串,而不是二进制数。
Which leaves the C# compiler to up the creek without a paddle, it must convert the attribute string to integers so it can generate the binary number as well. Clearly it cannot just let that go wrong without at least generating a warning. The assertion in the MSDN doc for CS1607 that this is benign is not terribly accurate, you really do end up with a resource that doesn't have the binary product version set. The odds that this ends up causing trouble are however not that great, other programs don't usually read it back and it tends to only be looked at by humans. The "Details" property sheet in Explorer's Properties dialog for the file displays it. The string, not the binary number.
所以,你需要考虑是只指定一个有效的版本号,因为它真正的的变通方法是的版本数。或者让你拥有对内容完全控制接管代非托管资源的自己。你写一个资源脚本做和RC.EXE编译。而且它告诉C#编译器项目+属性,应用程序选项卡,选择资源文件单选按钮。千万当心相当大的痛苦,你就会对自己造成,你现在还必须保持更新资源脚本,并同步与管理资源的任务。特别痛苦附属程序集我会说。
So workarounds you need to contemplate is to just specify a valid version number because it really is a version number. Or to take over generation of the unmanaged resource yourself so you have complete control over the content. Which you do by writing a resource script and compile with rc.exe. And tell the C# compiler about it with Project + Properties, Application tab, select the "Resource file" radio button. Do beware the considerable pain you'll inflict on yourself, you now also have the task to keep the resource script updated and in sync with the managed resources. Particularly painful for satellite assemblies I'd say.
这篇关于为什么警告CS1607"对于“产品版本”中指定的版本是不是在正常的“major.minor.build.revision'格式"产生的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!