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 numb
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();
}
}
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
To display the product version with .NET Compact Framework ( tested with with 2.0 and 3.5 ), you can use AssemblyHelper.getProductVersion() defined below.
For example, if the assembly version is defined like below in AssemblyInfo.cs file, the result of the method is "1.2.3".
Extract of AssemblyInfo.cs file :
[assembly: AssemblyVersion("1.2.3")]
Extract of AssemblyHelper.cs file :
using System;
using System.Reflection;
public static class AssemblyHelper
{
public static string getProductVersion()
{
Version assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version;
return String.Format("{0}.{1}.{2}", assemblyVersion.Major, assemblyVersion.Minor, assemblyVersion.Build);
}
}