c# – 为什么我不能使用反射加载AssemblyVersion属性?
发布时间:2020-12-15 08:09:53 所属栏目:百科 来源:网络整理
导读:assemblyinfo.cs文件具有AssemblyVersion属性,但是当我运行以下命令时: Attribute[] y = Assembly.GetExecutingAssembly().GetCustomAttributes(); 我明白了: System.Runtime.InteropServices.ComVisibleAttributeSystem.Runtime.CompilerServices.Runtime
assemblyinfo.cs文件具有AssemblyVersion属性,但是当我运行以下命令时:
Attribute[] y = Assembly.GetExecutingAssembly().GetCustomAttributes(); 我明白了: System.Runtime.InteropServices.ComVisibleAttribute System.Runtime.CompilerServices.RuntimeCompatibilityAttribute System.Runtime.CompilerServices.CompilationRelaxationsAttribute System.Runtime.InteropServices.GuidAttribute System.Diagnostics.DebuggableAttribute System.Reflection.AssemblyTrademarkAttribute System.Reflection.AssemblyCopyrightAttribute System.Reflection.AssemblyCompanyAttribute System.Reflection.AssemblyConfigurationAttribute System.Reflection.AssemblyFileVersionAttribute System.Reflection.AssemblyProductAttribute System.Reflection.AssemblyDescriptionAttribute 然而,我已无数次检查过我的代码中存在此属性: [assembly: AssemblyVersion("5.5.5.5")] …如果我尝试直接访问它,我会得到一个例外: Attribute x = Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(),typeof(AssemblyVersionAttribute)); //exception 我想我将无法使用该属性,但是.NET怎么没有读它呢? 解决方法
如果您正试图获得程序集版本,那么它非常简单:
Console.WriteLine("The version of the currently executing assembly is: {0}",Assembly.GetExecutingAssembly().GetName().Version); 该属性的类型为System.Version,具有Major,Minor,Build和Revision属性. 例如.版本1.2.3.4的程序集具有: >重大= 1>次要= 2> Build = 3>修订版= 4 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |