How to get the assembly version number in the Windows store app

Source: Internet
Author: User

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

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

There are many limitations to reflection in WinRT, assuming that the Windows store app references an assembly with a MyApp.Utils class called MyUtils , you can get MyApp.Utils the version number and file version number of the assembly using the following methods.

Get Assembly Version number

Method One

using System.Reflection;  Public Static string getassemblyversion () {    return assembly.load (new AssemblyName ("  Myapp.utils"))        . GetName (). Version.tostring ();}

Note that method one has two constraints, one requires knowing the full 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" (Windows runtime Component), method one returns the following error:

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

Method Two

using System.Reflection;  Public Static string getassemblyversion () {    returntypeof(myutils). GetTypeInfo (). Assembly.getname (). Version.tostring ();}

Method Two is available when the assembly output type is a class library or a Windows runtime component, with the restriction that you need to know a class in the assembly and then typeof(MyUtils).GetTypeInfo().Assembly get the version number of the assembly by getting the target assembly.

get 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 get custom attributes, which can be used to obtain AssemblyFileVersionAttribute the value of an attribute, that is, the file version number of the assembly.

Availability of

The above methods are available in Windows/windows Phone 8.1 Universal and in Windows UWP.

Reference

    • Customattributeextensions Class
    • AssemblyFileVersionAttribute Class

How to get the assembly version number in the Windows store app

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.