Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Duplicate 'System.Reflection.AssemblyInformationalVersionAttribute' attribute

I am trying to dive into the ASP.NET Core. So, I decided to try create a pet project, using the VS Code.

With the help of the dotnet cmd I created a solution, added projects into it (App, Tests, EF, Mapping, etc.) and setup references between the projects.

But now when I try to run the solution I am getting the Duplicate 'System.Reflection.AssemblyInformationalVersionAttribute' attribute error and a bunch of other strange errors. Here is a piece of the errors I am getting:

c:\Projects\dotNet\BestTongue\Utilities\objBinRemove\obj\Debug\netcoreapp3.0\objBinRemove.AssemblyInfo.cs(10,12): error CS0579: Duplicate 'System.Reflection.AssemblyCompanyAttribute' attribute [C:\Projects\dotNet\BestTongue\BestTongue.csproj]
c:\Projects\dotNet\BestTongue\Utilities\objBinRemove\obj\Debug\netcoreapp3.0\objBinRemove.AssemblyInfo.cs(11,12): error CS0579: Duplicate 'System.Reflection.AssemblyConfigurationAttribute' attribute [C:\Projects\dotNet\BestTongue\BestTongue.csproj]
...

enter image description here

enter image description here

I am not sure what else do I need to add to my question to make the problem solvable. So, please, ask all the necessary details in comments if I missed something.

I spent a lot of time trying to find a solution to the issue, but in vain.

UPDATE

As was recommended in the comments section I tried to use the solutions mentioned in the related question.

I tried to add the:

<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> <GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute> <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> <GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>

So, now my .csproj looks like that:

<Project Sdk="Microsoft.NET.Sdk">

  <ItemGroup>
    <ProjectReference Include="..\App\App.csproj" />
    <ProjectReference Include="..\Data\Data.csproj" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
  </ItemGroup>

  <PropertyGroup>
    <TargetFramework>netstandard3.0</TargetFramework>
    <GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
    <GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
    <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
    <GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
  </PropertyGroup>

</Project>

But I still see the same errors:

enter image description here

Also, I wrote a script which goes over all the projects and removes the *.AssemblyInfo.cs. After that I checked whether or not building project will bring the *.AssemblyInfo.cs back. And *.AssemblyInfo.cs does appear after the build again. Also, now (after the .csproj file modification) I got a new error:

C:\Program Files\dotnet\sdk\3.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(140,5): error NETSDK1045: The current .NET SDK does not support targeting .NET Standard 3.0. Either target .NET Standard 2.1 or lower, or use a version of the .NET SDK that supports .NET Standard 3.0. [C:\Projects\dotNet\BestTongue\Controllers\Controllers.csproj] C:\Program

Files\dotnet\sdk\3.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(140,5): error NETSDK1045: The current .NET SDK does not support targeting .NET Standard 3.0. Either target .NET Standard 2.1 or lower, or use a version of the .NET SDK that supports .NET Standard 3.0. [C:\Projects\dotNet\BestTongue\App\App.csproj]

It may be useful for someone who is trying to help me to check the solution locally. Here is the solution repository with the latest changes.

like image 597
qqqqqqq Avatar asked Jan 02 '20 23:01

qqqqqqq


Video Answer


2 Answers

This was spot on (Ian Kemp nos 1 above.) I was upgrading .net app to .net core 5, painful effort to rid this issue. Now all good. Do a file search on your .net core app (I assume 3.X is the same) and remove all the AssemblyInfo.cs files (.net core builds AssembleyInfo from the project file so doesn't matter if you delete these as well. Recompile and the problem should go away. One extra, make sure your Library (DLL) files are all 'Library' in the Property group... e.g.

<PropertyGroup>
    <OutputType>Library</OutputType>
    <TargetFramework>net5.0</TargetFramework>
    <GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
    <GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
    <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
  </PropertyGroup>
like image 106
John Irvine Avatar answered Oct 12 '22 21:10

John Irvine


I solved this by re-structuring my solution rather than deleting files or changing any settings.

My original structure looked like this, note how all projects were inside the solution folder:

Solution folder

  • Website project
  • Business project
  • Repository project
  • Database project

I re-structured it to look like this and now I no longer have the duplicate attribute errors:

Solution folder

  • Website project

Business folder

  • Business project

Repository folder

  • Repository project

Database folder

  • Database project
like image 41
Lars Passic Avatar answered Oct 12 '22 22:10

Lars Passic