1

在 .NETCore1.1 中,下一个代码

typeof(Program).GetTypeInfo().Assembly.GetCustomAttributes().ToList()

返回自定义程序集属性列表,其中之一是AssemblyTitleAttribute. 默认情况下,此属性值返回项目名称,但我如何设置任何其他值?

尝试添加程序集信息文件AssemblyInfo.cs,如何在此处描述,但出现错误

错误 CS0579:重复的“System.Reflection.AssemblyTitleAttribute”属性

4

1 回答 1

4

现在可以在.csproj或 using中定义属性AssemblyInfo.cs,但只能使用一个地方,否则会生成“重复”错误。

如果要使用AssemblyInfo.cs,请将以下内容添加到.csproj以避免重复错误:

<PropertyGroup>
  <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>

如果您对它的工作原理感兴趣,请查看GenerateAssemblyInfo 任务


否则删除AssemblyInfo.cs并将以下内容添加到您的.csproj文件中:

<PropertyGroup>
  <AssemblyTitle>My library</AssemblyTitle>
</PropertyGroup>
于 2017-06-03T14:55:19.873 回答