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