Getting the assembly version without loading it in the .NET Compact Framework

In the .NET Compact Framework 3.5 application, I perform version checking in a rather narrow cycle to find out if another assembly needs to be updated (have a new copy in another directory copied above it, then run it again).

The problem is that it Assembly.LoadFrom(path).GetName().Versionlocks the file and prevents the specified copying.

AssemblyName.GetAssemblyName(path)it would be the best way to get this (thanks to this SO answer ), since it does not constantly load the assembly into AppDomain and thus does not block the file, but it is not available in the Compact Framework.

I could create a new one AppDomain, but I cannot use a new method Loadthat is not supported in the Compact Framework.

As a last resort, I decided that I would allow the assembly to really boot with overload Assembly.Load(byte[]), which would lead to a "leak" of massive memory in a narrow cycle, since they were never unloaded. To counter the fact that I intended to first hash the array of assembly bytes and check the version cache for the previous hit. However, as you might have guessed, byte array overloading is Assembly.Load()not supported in the Compact Framework.

I also considered adding AssemblyFileVersions, as they are easier to check anyway, but this is one more thing in the growing heap of things that are not supported in the Compact Framework (thanks to this SO answer , so as not to try this).

Please tell me what I'm trying to do, so that I stop hating this structure so much?

+3
3

, P/Invoke GetFileVersionInfo, GetFileVersionInfoSize VerQueryValue, , . pinvoke.net - . GetFileVersionInfo, . , , , , , .

http://pinvoke.net/default.aspx/coredll/GetFileVersionInfo.html

, OpenNETCF OpenNETCF.Diagnostics.FileVersionInfo. , , .

+1

Mono.Cecil Mono, . , assemblyversion

+1

you can get this information using Mono.Cecil as stated in Firo, here is the F # code snippet:

open Mono.Cecil

let getAssembly (filename: string) =
  AssemblyDefinition.ReadAssembly(filename)

let getVersion (assembly: AssemblyDefinition) =
  let versionAttributeTypeName = typeof<AssemblyFileVersionAttribute>.FullName
  match assembly.CustomAttributes.FirstOrDefault(fun f ->f.AttributeType.FullName = versionAttributeTypeName) with
  | null -> None
  | a -> Some (a.ConstructorArguments.First().Value :?> string)

getAssembly @"path to assembly"
|> getVersion

output from FSI

val getAssembly : filename:string -> AssemblyDefinition
val getVersion : assembly:AssemblyDefinition -> string option
val it : string option = Some "15.2.4.0"
+1
source

All Articles