0

I have a version number in my AssemblyInfo.cs file like so:

[assembly: AssemblyInformationalVersion("0.0.0.2")]

Normally I can access this information using FileVersionInfo and I do have a reference to System.dll (where this class is normally defined) but the System.Diagnostics namespace does not seem to be available.

Here's the path that VS says is the System assembly I'm referencing:

C:\Program Files (x86)\Microsoft.NET\SDK\CompactFramework\v3.5\WindowsCE\System.dll

In short: How can I display the version string (AssemblyInformationalVersion) of my application in my application?

Edit: Using

Assembly.GetExecutingAssembly().GetName().Version.ToString()

returns "0.0.0.0" since that attribute is not defined in my AssemblyInfo.cs file.

Charlie Salts
  • 13,109
  • 7
  • 49
  • 78

2 Answers2

2

So are you trying to get your own app's version:

Debug.WriteLine(string.Format("My App Version: {0}",
    Assembly.GetExecutingAssembly().GetName().Version.ToString()));

or the version of the CF assembly:

Debug.WriteLine(string.Format("System.dll Version: {0}",
    typeof(int).Assembly.GetName().Version.ToString()));

EDIT1

or the actual native FileInfo version (I think this is the one you're after).

EDIT2

Or you could do this for a managed assembly:

var a = Assembly.GetExecutingAssembly().GetCustomAttributes(
    typeof(AssemblyInformationalVersionAttribute), true)
    .FirstOrDefault() as AssemblyInformationalVersionAttribute;
Debug.WriteLine(string.Format("AssemblyInformationalVersion: {0}",
a.InformationalVersion));
ctacke
  • 66,480
  • 18
  • 94
  • 155
  • The simpler solution was to edit the AssemblyInfo.cs file myself - VS neglected to add the correct attribute when the file was originally created. Thanks for the help, though. – Charlie Salts Jun 25 '12 at 16:03
  • Beware, though. It's common to see a "PocketPC" targeted build not put the AssemblyVersion into to native resource, but if you swap to "Windows CE" it does. It sounds like you're not worried about the native resource, however. – ctacke Jun 25 '12 at 16:20
  • As far as I am aware, I've nothing native going on - it's all managed. I've tested it on my device, and it works. It's not a mission-critical thing. – Charlie Salts Jun 25 '12 at 16:22
-1

The solution was to manually enter the following into AssemblyInfo.cs:

[assembly: AssemblyVersion("1.2.3.4")]

I'm not sure why Visual Studio omitted it, but by adding it,

Assembly.GetExecutingAssembly().GetName().Version

returns the expected value.

To sum up: I was using the correct code, but I had the wrong information in my AssemblyInfo.cs file.

Charlie Salts
  • 13,109
  • 7
  • 49
  • 78
  • In the question it was requested to query for "AssemblyInformationalVersion" not AssemblyVersion – JackGrinningCat Aug 03 '18 at 17:30
  • @JackGrinningCat It turns out the solution to my problem wasn't to display `AssemblyInformationalVersion` but to _set_ `AssemblyVersion`. In fact, I set both those as well as `AssemblyFileVersion` to have the same value using my MSBuild script. At this point, changing my eventual solution or changing the question would be to re-write history. I don't see that as being honest. – Charlie Salts Aug 03 '18 at 20:24