AssemblyFileVersion attribute is being ignored

孤街醉人 提交于 2019-12-11 02:48:37

问题


I am having a problem getting the AssemblyVersion to be different from the AssemblyFileVersion attributes in a class library I am working on.

So, I've tried creating an empty (apart from Class1.cs) class library to see if it's a setting somewhere, but I get the same behaviour.

It seems the AssemblyVersion attribute is just being ignored.

Here is the relevant bit from my AssemblyInfo.cs file ...

[assembly: AssemblyVersion("0.1")]
[assembly: AssemblyFileVersion("1.1.0.9")]

and here is how things look in windows explorer ...

Is there a setting somewhere that controls this?

EDIT: I've found one file where there is a difference, so it's not windows explorer showing the same value for two different fields, it's something to do with the way the DLL is generated from the compiler/linker ...


回答1:


The key problem here is that Windows doesn't know anything about attributes in a managed program. It reads the unmanaged file version resource. The one that's embedded in a C# assembly with the /win32res compile option. The compiler auto-generates it by default if you don't use that option, using the assembly attribute values you specified in AssemblyInfo.cs to create the resource.

But an unmanaged file version resource doesn't have a standard field to specify anything like [AssemblyVersion]. Only [AssemblyFileVersion]. The compiler actually emits it, the version resource is extensible. But Windows XP was the last version that still displays these custom fields. You can see that unmanaged resource by opening the assembly in Visual Studio with File + Open + File.

Yes, lame and annoying. The Windows group at MS does not like to cater to managed code.




回答2:


Right, found the answer :-)

You need to edit AssemblyInfo.cs and add the following at the bottom

[assembly: AssemblyInformationalVersion("4.4.4.4")]

That value is displayed in the "Product version" in explorer. The AssemblyInformationalVersion is optional. If not given, the AssemblyVersion is used.

More information on this topic is here




回答3:


Checking on my PC, it actually works ok.

Explorer:

Properties:

Others which are different are:

My windows explorer.exe version is 6.1.7601.17567 if that helps. Windows 7 SP1

Testing this myself on Visual Studio with

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

Gave the result:

So looks like Visual Studio is doing something wrong here.

来源:https://stackoverflow.com/questions/7886964/assemblyfileversion-attribute-is-being-ignored

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!