I need to display the .NET Compact Framework version number on the screen. I am using .NET CF 2.0 with Windows CE 4.0.
So far, I have been ignoring the version number completely. Do I need to add anything to the assembly? how do I retrieve it programmatically?
Unfortunately this does not apply to Compact Framework. The Application.ProductVersion
property doesn't exist in Compact Framework. The latest part of your answer applies though.
One more question: do these properties (major, minor, build, revision) get incremented automatically or do I set them whenever I want to? The way I see it, the revision should be automatically incremented with each new build.
System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Major System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Minor System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Build System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Revision
Source: http://msdn.microsoft.com/en-us/library/system.version.aspx
(Edit)
Application.ProductVersion Property
Gets the product version associated with this application.
Not Available In Compact Framework But System.Reflection.Assembly.GetExecutingAssembly().GetName().Version Is.
Source: http://msdn.microsoft.com/en-us/library/system.windows.forms.application.productversion.aspx
You can also use Version.ToString() passing the number of components to return as parameter:
System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(3)
This line returns Major.Minor.Build
Source: http://msdn.microsoft.com/en-us/library/bff8h2e1(VS.80).aspx
There is an AssemblyInfo.cs in your project where you can edit your assembly version. To automatically increment the revision you can use something like this: 1.0.3200.*
Source: http://msdn.microsoft.com/en-us/library/system.reflection.assemblyversionattribute(VS.80).aspx
I know this is an old question, but here is a solution I found using Reflection and Linq (reposted from my answer here).
First, I added this to the AssemblyInfo.cs (replace the string with whatever you want to use):
[assembly: AssemblyInformationalVersion("1.0.0.0 Alpha")]
Then, you can use this method to pull out the attribute (I placed it inside a static class in the AssemblyInfo.cs file). The method get's an array of all Assembly attributes, then selects the first result matching the attribute name (and casts it to the proper type). The InformationalVersion string can then be accessed.
//using System.Reflection;
//using System.Linq;
public static string AssemblyInformationalVersion
{
get
{
AssemblyInformationalVersionAttribute informationalVersion = (AssemblyInformationalVersionAttribute)
(AssemblyInformationalVersionAttribute.GetCustomAttributes(Assembly.GetExecutingAssembly())).Where(
at => at.GetType().Name == "AssemblyInformationalVersionAttribute").First();
return informationalVersion.InformationalVersion;
}
}
To get the normal "AssemblyVersion" attribute I used:
//using System.Reflection;
public static string AssemblyVersion
{
get
{
return Assembly.GetExecutingAssembly().GetName().Version.ToString();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With