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;}
CustomAttributeExtensions
class 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