2

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 ...

Windows Explorer Screen Grab

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 ...

enter image description here

Antony Scott
  • 21,690
  • 12
  • 62
  • 94
  • Product version != Assembly version. That looks like it is working correctly to me... – Marc Gravell Oct 25 '11 at 09:15
  • @Marc, so what does the AssemblyVersion attribute map to in windows explorer? – Antony Scott Oct 25 '11 at 09:16
  • pretty sure it *used* to display, but indeed I can't get it to display in win-7. It is entirely possible that the answer is simply: it doesn't impact explorer *at all*, but is still an important part of the assembly definition. – Marc Gravell Oct 25 '11 at 09:19
  • I'm sure it used to display the different values, I just checked and can only find one file in the project I am working on which has different product/file versions. log4net has 1.2.10.0 (file) and 1.2 (product). Now I know I was looking at the wrong thing in explorer, apart from being a bit cheesed off, I'd like to know how/where I can check the assembly version attribute. Hmm, perhaps reflector is my friend in this instance. – Antony Scott Oct 25 '11 at 09:30
  • it might be that my memory of displaying both is going all the way back to XP – Marc Gravell Oct 25 '11 at 09:34

3 Answers3

5

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.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
4

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

Community
  • 1
  • 1
Simon Hughes
  • 3,534
  • 3
  • 24
  • 45
  • yeah, I found that attribute, but didn't try it out since I was just trying to check what the AssemblyVersion was. thanks. – Antony Scott Oct 25 '11 at 10:15
  • 1
    I just had different `AssemblyVersion` and `AssemblyFileVersion` entries, and the **`AssemblyFileVersion`** was used for Product and File Version in Explorer. (Could still "fix" `Product version` with `AssemblyInformationalVersion`, but that's slightly contra what you've got, above. I think if no `AssemblyInformationalVersion` and no `AssemblyFileVersion`, **then** `AssemblyVersion` is used.) – ruffin Nov 19 '13 at 18:32
1

Checking on my PC, it actually works ok.

Explorer:

enter image description here

Properties:

enter image description here

Others which are different are: enter image description here

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: enter image description here So looks like Visual Studio is doing something wrong here.

Simon Hughes
  • 3,534
  • 3
  • 24
  • 45