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?
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:
AssemblyInformationalVersion
defaults toAssemblyFileVersion
if it is not specified. Likewise,AssemblyInformationalVersion
andAssemblyFileVersion
default toAssemblyVersion
if both are not specified.In your example, the AssemblyInfo.cs file did not include
AssemblyInformationalVersion
, so it defaults to the value ofAssemblyFileVersion
. As you will see below,AssemblyInformationalVersion
maps to theFileVersionInfo.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 theFileVersionInfo.ProductVersion
property, which is non-intuitive. The attribute should more properly be namedAssemblyProductVersion
. And apparently, a title is also a description, etc.That said, how do we retrieve these (and related) values in code? Like this:
In the case of
AssemblyVersion
, use this: