How can I get the executing assembly version information in a Windows Store App?

前端 未结 1 983
你的背包
你的背包 2021-02-07 18:12

While porting an application to the Windows Store, I noticed the .NETCore Framework does not include:

System.Reflection.Assembly.GetExecutingAssembly()

相关标签:
1条回答
  • 2021-02-07 18:55

    I am using this :

    public string GetApplicationVersion()
    {
      var ver = Windows.ApplicationModel.Package.Current.Id.Version;
      return ver.Major.ToString() + "." + ver.Minor.ToString() + "." + ver.Build.ToString() + "." + ver.Revision.ToString();
    }
    

    And if you want assembly version you can get it from Version attribute :

    public string GetAssemblyVersion(Assembly asm)
    {
      var attr = CustomAttributeExtensions.GetCustomAttribute<AssemblyFileVersionAttribute>(asm);
      if (attr != null)
        return attr.Version;
      else
        return "";
    }
    

    For example using main App's assembly :

    Assembly appAsm = typeof(App).GetTypeInfo().Assembly;
    string assemblyVersion = GetAssemblyVersion(appAsm);
    
    0 讨论(0)
提交回复
热议问题