Search code examples
.net.net-core.net-assemblyassembly-attributes

How to set AssemblyTitleAttribute in NETCore1.1


In .NETCore1.1, next code

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

returns list of custom assembly attributes and one of them is AssemblyTitleAttribute. By default this attribute value returns project name, but how can I set any other value?

Tried to add assembly information file AssemblyInfo.cs how it's described here, but getting error

error CS0579: Duplicate 'System.Reflection.AssemblyTitleAttribute' attribute


Solution

  • Right now properties could be defined in .csproj or using AssemblyInfo.cs, but only the one place could be used, otherwise "Duplicate" errors are generated.

    If you want to use AssemblyInfo.cs, add the following into .csproj to avoid duplication errors:

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

    If you are interesting how does it work, look into GenerateAssemblyInfo task.


    Otherwise remove AssemblyInfo.cs and add the following into your .csproj file:

    <PropertyGroup>
      <AssemblyTitle>My library</AssemblyTitle>
    </PropertyGroup>