Querying AssemblyInformationalVersionAttribute while targeting Windows Mobile 5.0 PocketPC
-
16-06-2021 - |
Question
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.
Solution 2
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.
OTHER TIPS
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));