How to get the file version with out loading it into AppDomain?

G

Guest

I need to get the version of an executable file which is an .NET CF assembly. But I found that there is no FileVersionInfo class, neither the static function GetAssemblyName in class AssemblyName. How can I get the file version without loading into AppDomain with using System.Reflection.Assembly.LoadFrom

th

BTW, Is there an explicitly way to "unload" an assembly loaded by reflection? Or how can I know whether and when the memory hold by the loaded assembly is released?
 
A

Alfred Gary Myers Jr.

Hi,

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

Hope this helps.

Alfred Gary Myers Jr.
Yuma Informática




Sumtec said:
I need to get the version of an executable file which is an .NET CF
assembly. But I found that there is no FileVersionInfo class, neither the
static function GetAssemblyName in class AssemblyName. How can I get the
file version without loading into AppDomain with using
System.Reflection.Assembly.LoadFrom ?
thx

BTW, Is there an explicitly way to "unload" an assembly loaded by
reflection? Or how can I know whether and when the memory hold by the loaded
assembly is released?
 
G

Guest

Thx, but what I mean is to get the version of a file which is not the executing one
Thank Q all the same
 
D

Daniel Moth

Hi

I have the exact same requirement.. Currently I load the assembly to read
its version but like you I have found no way to unload it or another way of
getting its version...

Did you find a solution?

Cheers
Daniel
 
B

Brian Smith [MSFT]

There is no mechanism to read the assembly version in .NET CF without
loading the assembly. And sadly, there is no way to unload an assembly in
this version of .NET CF.

One potential work-around would be to use Win32 resources. This mechanism
is used by .NET CF itself for its own libraries. When the libraries are
built, a Win32 "version" resource is added (this can be done from the C#
command line using the /win32res compiler switch or from Visual Studio).
Then if anyone needs to know their version, they may be queried by
p/invoking to the Win32 version APIs (see
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui
/windowsuserinterface/resources/versioninformation.asp for some more
information about that). If you have built the assembly that you are
interested in querying, this mechanism could work for you. Otherwise, there
is no guarantee that the version resource exists or that it is accurate.

This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

Daniel Moth

Hi

Thanks for your suggestion... I will definitely look into it when I am back
from holidays... In the meantime maybe you have some thoughts on related
questions of a specific scenario:

<from another thread on the same subject>
Imagine an EXE using a DLL (a) that uses a DLL (b) that uses a DLL (c)....

Code running in the leaf DLL (c) has to know the version of the EXE. The
only way I found of doing that is to Assembly.LoadFrom(exePath)...

So:
Is there an alternative way of achieving the above?
Assuming not, I don't know how to force unloading the assembly... Is that
bad?
And my afterthought was: Since the exe is already running does it actually
get loaded twice or am I worrying for nothing?
</from another thread on the same subject>

Cheers
Daniel
 
P

Peter Foot [MVP]

You may be interested to sign up for the OpenNETCF Smart Device Framework
Beta (beta.opennetcf.org). We have an implementation of the
System.Diagnostics.FileVersionInfo (missing in the Compact Framework) which
allows you to query the Win32 file version of a file. This will allow you to
get the version without loading the managed DLL using Assembly.Load.

Peter

--
Peter Foot
Windows Embedded MVP
OpenNETCF.org Senior Advisor
www.inthehand.com | www.opennetcf.org
 
B

Brian Smith [MSFT]

Loading an assembly that is already loaded doesn't have any serious cost.

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top