Programmatically Get Assembly Version

In this tip I will discuss how we can get assembly version programmatically  from a caller application.  This can be done easily by taking help of Reflection.  Assembly  Class contains a static method called GetAssemblyFullName() which gets the assembly that contains the code that is currently executing.

FullName is a properties under Assembly class which will return the full name of assembly the contains Assembly name, Version , Culture and Public Key Token.

 

Bellow is the code snippet for a sample assembly where I have created on Static Method Called GetAssemblyVersion.

public class ClassTest
{
public ClassTest()
{

}

public static string SampleMethod()
{
return "Sample Method";
}

public string GetAssemblyVersion()
{
return Assembly.GetExecutingAssembly().FullName;
}

}

Related Read : Automate Assembly Build Version

Add the created assembly as reference in a console application ( or any ) and call the GetAssemblyVersion() method as shown in below snippet.

ClassTest classTest = new ClassTest();
Console.WriteLine(classTest.GetAssemblyVersion());

You will get below output

image

Abhijit Jana

Abhijit runs the Daily .NET Tips. He started this site with a vision to have a single knowledge base of .NET tips and tricks and share post that can quickly help any developers . He is a Former Microsoft ASP.NET MVP, CodeProject MVP, Mentor, Speaker, Author, Technology Evangelist and presently working as a .NET Consultant. He blogs at http://abhijitjana.net , you can follow him @AbhijitJana . He is the author of book Kinect for Windows SDK Programming Guide.