How to obtain the assembly version number in the Windows Store application.

Source: Internet
Author: User

How to obtain the assembly version number in the Windows Store application.

This article is a personal blog backup article, the original address:

Http://validvoid.net/windows-store-app-get-assembly-version/

WinRT imposes many limitations on reflection. Assume that the Windows Store application references an assembly.MyApp.Utils, One of the classes is calledMyUtils, You can use the following method to obtain the AssemblyMyApp.Utils.

Obtain the assembly version number

Method 1

using System.Reflection;public static string GetAssemblyVersion(){    return Assembly.Load(new AssemblyName("MyApp.Utils"))        .GetName().Version.ToString();}

 

Note that method 1 has two constraints: one is to know the complete display name of the Assembly, and the other is that the Assembly output type must be a Class Library ). When the Assembly output type is Windows Runtime Component, method 1 returns the following error:

Could not load file or assembly 'MyApp.Utils, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.  

Method 2

using System.Reflection;public static string GetAssemblyVersion(){    return typeof(MyUtils).GetTypeInfo().Assembly.GetName().Version.ToString();}

 

Method 2 can be used when the Assembly output type is a class library or a Windows runtime component. The restriction is that you need to know a class in the Assembly and then passtypeof(MyUtils).GetTypeInfo().AssemblyGet the target assembly, and then get the assembly version number.

Obtain the Assembly file version number
using System.Reflection;public static string GetAssemblyFileVersion(){    return        CustomAttributeExtensions.GetCustomAttribute(            typeof(MyUtils).GetTypeInfo().Assembly).Version;}

 

CustomAttributeExtensionsClass contains static methods that can obtain custom features.AssemblyFileVersionAttributeThe value of the feature, that is, the file version number of the Assembly.

Availability

The above method is available in Windows/Windows Phone 8.1 Universal and Windows 10 UWP.

Reference

  • CustomAttributeExtensions Class
  • AssemblyFileVersionAttribute Class

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.