Eric Eric -4 years ago 326
C# Question

c# How to get the version of This current executable .exe

I have been using this code to obtain my programs version:

public string progVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();

However, it doesn't always seem to grab the version I'm expecting. I don't really understand how this works entirely or what it's doing.

I think it is impart because I'm launching my program from another program then it appears to grab the version of the program that launched it instead, or the 'GetExecutingAssembly()' I'm assuming references the program that executed my program, like so:


Is there a more reliable way to get the program version of the actual program at the time I ask for it?

Perhaps even launch my program without leaving some kind of trail, as if the user themselves just launched it.

Thanks for any help!

Answer Source

You could use the Assembly property of a known type via typeof which is defined in your application to ensure you got the 'correct' assembly and then retrieve the version of that, e.g.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download