阅读程序集的作者 [英] Read the Authors of an Assembly
问题描述
读取程序集的一些元数据非常容易,只需加载Assembly
,然后获取自定义属性,例如:
It's quite easy to read some metadata of an assembly, just load the Assembly
and then get the custom attributes, for example:
Assembly assembly = Assembly.GetExecutingAssembly();
AssemblyTitleAttribute? attribute = assembly.GetCustomAttribute<AssemblyTitleAttribute>();
string? title = attribute?.Title;
您可以将 AssemblyTitleAttribute
替换为其他一些内容,例如 Copyright
、Trademark
、Description
、版本
,但我找不到 Authors
的内容(此元数据可以设置在与其他元数据相同的位置,位于项目解决方案的包选项卡上).
You can replace the AssemblyTitleAttribute
by a few others like Copyright
, Trademark
, Description
, Version
but I'm unable to find something for the Authors
(this metadata can be set at the same location than the other, on the package Tab of the project's solution).
知道为什么缺少此属性以及如何读取它的值吗?(我使用的是 dotnet 标准 2.1)
Any idea why this attribute is missing and how it would be possible to read it's value? (I'm using dotnet standard 2.1)
推荐答案
没有程序集Attribute
for Authors
也不能查询通过反射或Shell32
There is No assembly Attribute
for Authors
neither can it be queried via Reflection or Shell32
这里是 AssembyInfo 属性和 作者
不是其中之一
Here's a list of AssembyInfo attributes and Authors
is not one of them
根据问题中更新的屏幕截图,您指的是 Project>Properties>Package
视图,而您在此处看到的字段是 AssemblyInfo 和;Nuget 元数据属性
As per the updated screen shot in the question, you are referring to Project>Properties>Package
view and the fields you see here are a mixture of AssemblyInfo & Nuget Metadata Properties
Copyright
和 Description
等属性对两者都是通用的
Properties such as Copyright
and Description
are common for both
其中PackageId
、Authors
、PackageVersion
等属性是Nuget Metadata 属性,无法从中查询大会.
Nuget 元数据属性是用作打包过程输入的属性列表
Where as properties such as PackageId
, Authors
, PackageVersion
are Nuget Metadata properties which cannot be queried from the assembly.
Nuget Metadata Properties are a list of properties that are used as inputs to the packing process
为什么我们甚至将 Authors 作为 Project>Properties>Package
中的一个字段?
Why do we even have Authors as a field in Project>Properties>Package
?
- 这样它就可以被 nuget.org 引用以显示作者姓名
来自 微软 文档
作者: 以分号分隔的包作者列表,与 nuget.org 上的配置文件名称匹配.这些显示在 NuGet 中nuget.org 上的图库,用于交叉引用包相同的作者.
Authors: A semicolon-separated list of packages authors, matching the profile names on nuget.org. These are displayed in the NuGet Gallery on nuget.org and are used to cross-reference packages by the same authors.
参考:
这篇关于阅读程序集的作者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!