Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Version number in .NET Compact Framework application

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.

like image 635
sarsnake Avatar asked Feb 09 '09 21:02

sarsnake


3 Answers

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

like image 83
VBNight Avatar answered Nov 15 '22 11:11

VBNight


  • 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

like image 27
Malik Amurlayev Avatar answered Nov 15 '22 10:11

Malik Amurlayev


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();
    }
}
like image 42
jarmst Avatar answered Nov 15 '22 12:11

jarmst