How to read the version number from the assembly

by Edward 19 February 2011 16:15

I was recently working on a project where it was important to display the version number of the code on the page for testing purposes as well as making sure the correct set of code goes to production. If you don't use a build server, or just copy your code over to your hosting space, then the following might be of help. By using reflection you can get the major, minor, build, and revision numbers of the assembly and the display it on your web page, or use however you need too.

The following code sample will help you with getting the version number of your application.

        private static void Main(string[] args)
        {
            //Get Application version details
            ApplicationDetails applicationDetails = new ApplicationDetails();
            string versionNumber = applicationDetails.GetVersion();
        }  
    class ApplicationDetails
{
/// <summary>
/// Gets the version.
/// </summary>
public string GetVersion()
{
return GetType().Assembly.GetName().Version.ToString();
}

}

 

You can set the version number to auto increment, by setting it in the properties window of your application.

Tags: , ,

ASP.NET | Development Resources | Other

Comments are closed