Version number in .NET Compact Framework application

后端 未结 4 928
陌清茗
陌清茗 2021-02-10 00:39

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

4条回答
  •  离开以前
    2021-02-10 00:51

    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();
        }
    }
    

提交回复
热议问题