Rob Sobers
Rob Sobers

Reputation: 21125

How can I determine my root calling assembly's version number at runtime? (.NET)

Example:

MyProgram.exe is executed. It calls MyClassLibrary1.dll which calls MyClassLibrary2.dll. How can I determine from within MyClassLibrary2.dll what the assembly version of MyProgram.exe is?

Is this possible?

Thanks.

Upvotes: 0

Views: 708

Answers (2)

Mehrdad Afshari
Mehrdad Afshari

Reputation: 421968

System.Reflection.Assembly.GetEntryAssembly().GetName().Version

Upvotes: 5

JaredPar
JaredPar

Reputation: 754545

EDIT My answer will only work if the DLL has a reference to the actually EXE which would be rather odd to do.

Try the following

typeof(SomeTypeInMyProgram).Assembly.GetName().Version

This will return a Version structure that you can use to analyze the version of MyProgram.exe.

Upvotes: 0

Related Questions