Question

In my server app, I can get File version info this way:

FileVersionInfo currentVersion = FileVersionInfo.GetVersionInfo(filePath);

...but that trick doesn't seem to work in the Compact Framework (I get, "The type or namespace name 'FileVersionInfo' could not be found (are you missing a using directive or an assembly reference?)"

It seems that the "using" I need in my server/Web API (.NET 4.5.1) app is System.Diagnostics, but adding that to my CF app leaves the using statement greyed out (and doesn't afford the resolution of the err msg shown above).

Do I need to add a specific assembly reference, coupled with a particular "using" to get this to work?

Or do I need to use custom CF code for this, such as that found here?

UPDATE

At the article linked to above, it says, "Getting file version info in the Compact Framework is pretty simple – provided the file you want info on is a managed assembly."

So, okay: what is the simple way? I'll try that first, before I go leaping through fiery hoops. And I know this question will seem naive to many, but: Is a custom .exe we have created (an "in-house" app) "native" or "managed"? I tried googling the difference between the two, but didn't find a definition...

Was it helpful?

Solution

It depends what you mean by "version". As with everything, it's not as simple as it may seem. managed assemblies have a managed version, which is what is set in your AssemblyVersion attribute, something like this:

[assembly: AssemblyVersion("3.0.2")]

This is the version that the managed loader uses and the version that ends up in the type names of the types in the assembly. It's really the "important" version number. It's the version you get if you look at an Assembly's Version Property.

However, it's not the version number that you see when you look at "File -> Properties" in something like Windows Explorer.

Explorer looks at the file for native VERSION_INFO headers, which are completely disconnected from the managed version. For a desktop app, it's set using the AssemblyFileVersion attribute. The Compact Framework, however, doesn't have support for setting that version information. You can work around that if you want, but the CF also has no inherent way to read it back. That's why the blog entry you refer to is talking about - getting the native version info.

So you have to figure out which version you're interested in, then follow the path for setting and getting it. Generally speaking, if it's a managed assembly I try real hard to avoid ever dealing with the native AssemblyFileVersion because it's really not useful for much of anything. Instead I just work with the AssemblyVersion. This is true for CF, desktop or Mono.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top