Windows Store 应用中获取程序集版本号的方法
本文为个人博客备份文章,原文地址:
http://validvoid.net/windows-store-app-get-assembly-version/
WinRT 中对反射做了很多限制,假设 Windows Store 应用引用了一个程序集 MyApp.Utils
,其中有一个类叫做 MyUtils
,可以使用以下方法获得程序集 MyApp.Utils
的版本号和文件版本号。
获得程序集版本号
方法一
- using System.Reflection;
- public static string GetAssemblyVersion()
- {
- return Assembly.Load(new AssemblyName("MyApp.Utils"))
- .GetName().Version.ToString();
- }
注意方法一有两个限制条件,一是要求知道程序集的完整显示名称;二是程序集输出类型必须是“类库”(Class Library)。当程序集输出类型是“Windows 运行时组件”(Windows Runtime Component)时,方法一将返回如下错误:
Could not load file or assembly 'MyApp.Utils, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
方法二
- using System.Reflection;
- public static string GetAssemblyVersion()
- {
- return typeof(MyUtils).GetTypeInfo().Assembly.GetName().Version.ToString();
- }
方法二在程序集输出类型为类库或者 Windows 运行时组件时均可用,其限制条件是需知道程序集中的一个类,再通过 typeof(MyUtils).GetTypeInfo().Assembly
取得目标程序集,进而获得程序集的版本号。
获得程序集文件版本号
- using System.Reflection;
- public static string GetAssemblyFileVersion()
- {
- return
- CustomAttributeExtensions.GetCustomAttribute(
- typeof(MyUtils).GetTypeInfo().Assembly).Version;
- }
CustomAttributeExtensions
类包含了可以获得自定义特性的静态方法,可以通过此类,获得 AssemblyFileVersionAttribute
特性的值,也就是程序集的文件版本号。
可用性
以上方法在 Windows/ Windows Phone 8.1 Universal 以及 Windows 10 UWP 中测试可用。
参考
Windows Store 应用中获取程序集版本号的方法的更多相关文章
- C#中获取程序集版本号的方法
我的方法: string version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); 方法一: public v ...
- python中获取python版本号的方法
import platform print platform.python_version()
- python中获取python版本号的方法【转】
原文 python3 #!/usr/bin/python # 第1种方法 import platform print(platform.python_version()) >>> i ...
- 如何在 Windows Phone 8 中获取手机的当前位置
原文 如何在 Windows Phone 8 中获取手机的当前位置 适用于:仅限于 Windows Phone 8. 本主题演示如何使用 Windows Phone 位置 API 确定手机的当前位置. ...
- Windows Server 2008中关闭事件跟踪程序的方法
Windows Server 2008跟Windows Server 2003一样,在关机的时候会弹出一个“关闭事件跟踪程序”窗口,当然微软这么做是处于安全的考虑啦,但是如果我们只是个人用用的话,那就 ...
- android中获取root权限的方法以及原理(转)
一. 概述 本文介绍了android中获取root权限的方法以及原理,让大家对android 玩家中常说的“越狱”有一个更深层次的认识. 二. Root 的介绍 1. Root 的目的 可以让我们拥有 ...
- dede织梦栏目页和文章页中获取当前栏目名称方法
一般情况下,在dede织梦系统中列表页.栏目页和文章页中获取当前所在栏目名称只需要代码:{dede:type}[field:typename]{/dede:type}即可,不需要定义ID,默认的就是当 ...
- Android中获取文件路径的方法总结及对照
最近在写文件存贮,Android中获取文件路径的方法比较多,所以自己也很混乱.找了好几篇博客,发现了以下的路径归纳,记录一下,以备不时之需 Environment.getDataDirectory() ...
- LoadRunner中获取当前系统时间方法
LoadRunner中获取当前系统时间方法 发表于:2017-6-02 11:41 作者:人生_0809 来源:51Testing软件测试网采编 字体:大 中 小 | 上一篇 | 下一篇 | 打 ...
随机推荐
- 高产的母猪之 python __init__全解
python __init__.py python 识别是不是一个模块的标准是目录下有无 __init__.py 模糊导入 模糊导入中的*中的模块是由__all__来定义的,__init__.py的 ...
- 洛谷P3628 [APIO2010]特别行动队(斜率优化)
传送门 先写出转移方程$$dp[i]=max\{dp[j]+a*(sum[i]-sum[j])^2+b*(sum[i]-sum[j])+c\}$$ 假设$j$比$k$更优,则有$$dp[j]+a*(s ...
- U19464 山村游历(Wander) LCT维护子树大小
\(\color{#0066ff}{ 题目描述 }\) 在一个偏远的小镇上,有一些落后的山村.山村之间通过一些道路来连接.当然有的山村可能不连通. 一年当中会发生很多大事,比如说有人提议要在山村\(i ...
- P4015 运输问题
\(\color{#0066ff}{题目描述}\) W 公司有 m 个仓库和 n 个零售商店.第 i 个仓库有 \(a_i\) 个单位的货物:第 j 个零售商店需要 \(b_j\) 个单位的货物. 货 ...
- java.lang.Exception: No tests found matching(Junit测试异常)
java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=save], {ExactMatcher:fDispl ...
- mysql 常用函数。。
FIND_IN_SET(str,strlist) ,strlist 是 一个 由 逗号 分割的字符串,要注意 strlist 不能有逗号.. 它 等于 where str in (1,2,3***) ...
- 以Tkinter模块来学习Python实现GUI(图形用户界面)编程
tk是什么:它是一个图形库,支持多个操作系统,使用tcl语言开发的.tkinter是Python内置的模块, 与tk类似的第三方图形库(GUI库)还有很多,比如:Qt,GTK,wxWidget,wxP ...
- BZOJ1725】[Usaco2006 Nov]Corn Fields牧场的安排 状压DP
Description Farmer John新买了一块长方形的牧场,这块牧场被划分成M列N行(1<=M<=12; 1<=N<=12),每一格都是一块正方形的土地.FJ打算在牧 ...
- 计算机学院大学生程序设计竞赛(2015’12)The collector’s puzzle
Problem Description There is a collector who own many valuable jewels. He has a problem about how to ...
- InterruptionInJava
package com.test; public class InterruptionInJava implements Runnable{ public static void main(Strin ...