Extracting the Assembly Version in .Net

Posted by OmegaMan at July 16, 2007

Category: How To, Winforms

I like to place the version number of the current application either on the console output or the title bar of the Winform. Using the below method I am able to extract the current assemblies information and return the version info to be displayed.

using System.Reflection;
using System.Diagnostics;

~
// Place in local code
Assembly ass = Assembly.GetExecutingAssembly();
string version;

if (ass != null)
{
    FileVersionInfo FVI = FileVersionInfo.GetVersionInfo(ass.Location);

    version = String.Format("{0} Version ({1:0}.{2:0})",
                  FVI.ProductName,
                  FVI.FileMajorPart.ToString(),
                  FVI.FileMinorPart.ToString());
}
else
{
   version = "Unknown";
}
Share

2 Comments

  1. William Jones says

    This is really helpful, but I seem to be unable to find the Revision portion of the Assembly version. Am I just missing it, or is it not accessible this way?

    Thanks,
    William Jones

    Reply
  2. David Woosley says

    Ditto what William said. Revision number?

    Reply

Leave a comment

(required)
(required) (will not be published)

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