Reputation: 69
I want to find the dll version when the path is specified. Suppose path = "progfiles/harry/sample.dll". How to find the sample.dll version. Since I am using .net framework 3.5 SP1, I cannot use FileVersionInfo. I tried Assembly.LoadFrom. But the problem I am facing with LoadFrom is "If an assembly with the same identity is already loaded, LoadFrom returns the loaded assembly even if a different path was specified."
Upvotes: 0
Views: 2045
Reputation: 2715
You can use AssemblyName
:
var assemblyName = AssemblyName.GetAssemblyName(assemblyPath);
System.Diagnostics.Debug.WriteLine(assemblyName.Version);
Upvotes: 0
Reputation: 101142
Anyway, you could just load your assembly into another AppDomain.
var domain = AppDomain.CreateDomain("tmp");
var version = domain.Load().GetName(path).Version;
EDIT:
You are targeting Windows CE, so can use the GetFileVersionInfo function.
Here is a full code sample how to use this function from within .Net/C#.
Upvotes: 1
Reputation: 770
Example code to find version of DLL library:
Version ver = Assembly.LoadFrom("Library.dll").GetName().Version;
Edit 1: OK, for getting already executing assembly you can try this example:
Assembly SampleAssembly;
SampleAssembly = Assembly.GetAssembly(ObjectLoadedFromDLL.GetType());
Version ver = Assembly.GetExecutingAssembly().GetName().Version;
And links to MSDN this full documentation of this method: Assembly.GetExecutingAssembly Method
Upvotes: 0