Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS 2017 Build Errors - Duplicate Attributes in AssemblyInfo.cs

I am developing a web application which started life by running dotnet new angular (Clear blog explanation of usage).

To extend the functionality of the default code I started developing a Web API. I added 3 new .Net Core Library Projects named Shared, Scheduling and Scheduling_Tests.

Some Domain Model classes were defined in Scheduling, some base classes were defined in Shared and finally some NUnit tests were defined in ShedulingTests.

When I build the Solution, 2 new folders appear in my Web Application project: Shared and Scheduling. I also get build errors like the following:

Error   CS0579  Duplicate 'System.Reflection.AssemblyCompanyAttribute'

I'm not sure where to go with this one, any advise would be very welcome.

like image 271
TDC Avatar asked Jul 27 '17 11:07

TDC


1 Answers

This happens because the new .NET tools automatically create the attributes and add them to the assembly, so they now appear twice in the build.

There are two ways to fix it:

  1. Delete AssemblyInfo.cs

  2. Keep AssemblyInfo.cs, but add tags to your CSProj file to suppress the attributes in AssemblyInfo.

For example:

<PropertyGroup>
  <TargetFramework>netstandard2.0</TargetFramework>
  <GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
  <GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
  <GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>  
  <GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
  <GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
  <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
  <GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>    
</PropertyGroup>

(Thanks to https://johnkoerner.com/csharp/dealing-with-duplicate-attribute-errors-in-net-core/)

like image 121
Neil Avatar answered Sep 20 '22 19:09

Neil