AssemblyVersion and AssemblyFileVersion

Every C# project typically contains a prefab file called AssemblyInfo.cs which contains the lines

// You can specify all the values or you can default the Revision and Build Numbers 
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.2.*")]
[assembly: AssemblyFileVersion("")]

Though these assembly attributes are named quite similarly, they must be retrieved in different ways.

The AssemblyFileVersion attribute is a list element of the return value of GetCustomAttributes():

string fileversion = null;
var a = Assembly.GetExecutingAssembly()
  .GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true)
if (a != null)
  fileversion = a.Version;

Compare this to the processing of AssemblyVersion, which can be retrieved from the current assembly using

string assemblyversion =

(I noticed that I wrote about this topic many years ago, but I didn’t remember, and probably you didn’t either 😉 )

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.