2017-06-03 74 views
1

在.NETCore1.1,下面的代码如何NETCore1.1

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

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

试图添加组件信息文件AssemblyInfo.cs它是如何描述here,但得到错误

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

回答

4

眼下性质可以定义在.csproj或使用AssemblyInfo.cs,但只有一个地方可以使用,否则会产生“重复”错误。

如果你想使用AssemblyInfo.cs,添加以下为.csproj,以避免重复错误:

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

如果你有兴趣它是如何工作,看看GenerateAssemblyInfo task


否则删除AssemblyInfo.cs,并添加以下到您的.csproj文件:

<PropertyGroup> 
    <AssemblyTitle>My library</AssemblyTitle> 
</PropertyGroup> 
+0

太好了!非常感谢! false是我所需要的 –