读取程序集的某些元数据,只需加载Assembly
,然后获取自定义属性,就很容易,例如:
Assembly assembly = Assembly.GetExecutingAssembly();
AssemblyTitleAttribute? attribute = assembly.GetCustomAttribute<AssemblyTitleAttribute>();
string? title = attribute?.Title;
您可以将AssemblyTitleAttribute
替换为Copyright
,Trademark
,Description
,Version
等一些其他名称,但我找不到Authors
的某些内容(可以在在项目解决方案的程序包选项卡上,位置与其他位置相同)。
任何想法,为什么缺少此属性以及如何读取它的值? (我使用的是dotnet标准2.1)
默认情况下,Attribute
有No个程序集Authors
这里是IEnumerable<Attribute>
个项目的列表,Authors
不是其中之一
System.Runtime.CompilerServices.CompilationRelaxationsAttribute
System.Runtime.CompilerServices.RuntimeCompatibilityAttribute
System.Diagnostics.DebuggableAttribute
System.Reflection.AssemblyTitleAttribute
System.Reflection.AssemblyDescriptionAttribute
System.Reflection.AssemblyConfigurationAttribute
System.Reflection.AssemblyCompanyAttribute
System.Reflection.AssemblyProductAttribute
System.Reflection.AssemblyCopyrightAttribute
System.Reflection.AssemblyTrademarkAttribute
System.Runtime.InteropServices.ComVisibleAttribute
System.Runtime.InteropServices.GuidAttribute
System.Reflection.AssemblyFileVersionAttribute
System.Runtime.Versioning.TargetFrameworkAttribute
但是,我相信您指的是ExtendedFileAttributes
here
例如,您可以更改MS-Word文档的作者属性,但默认情况下不更改exe
的作者属性,因为每种文件类型都具有特定的扩展文件属性,并且并非所有属性都是可写的。
参考: