Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the executing assembly version?

I am trying to get the executing assembly version in C# 3.0 using the following code:

var assemblyFullName = Assembly.GetExecutingAssembly().FullName; var version = assemblyFullName .Split(',')[1].Split('=')[1]; 

Is there another proper way of doing so?

like image 284
user1 Avatar asked Feb 09 '11 04:02

user1


1 Answers

Two options... regardless of application type you can always invoke:

Assembly.GetExecutingAssembly().GetName().Version 

If a Windows Forms application, you can always access via application if looking specifically for product version.

Application.ProductVersion 

Using GetExecutingAssembly for an assembly reference is not always an option. As such, I personally find it useful to create a static helper class in projects where I may need to reference the underlying assembly or assembly version:

// A sample assembly reference class that would exist in the `Core` project. public static class CoreAssembly {     public static readonly Assembly Reference = typeof(CoreAssembly).Assembly;     public static readonly Version Version = Reference.GetName().Version; } 

Then I can cleanly reference CoreAssembly.Version in my code as required.

like image 139
Chris Baxter Avatar answered Sep 24 '22 21:09

Chris Baxter