11

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.

qqqqqqq
  • 1,831
  • 1
  • 18
  • 48
  • 1
    You have multiple `*.AssemblyInfo.cs` files in a single project that are causing your errors. I am not sure why you have these files, as .NET no longer uses `AssemblyInfo.cs` as of Core, so just delete them and your errors will go away. – Ian Kemp Jan 03 '20 at 00:16
  • 1
    In your .csprojs file, just make sure you have this: false – Jaliya Udagedara Jan 03 '20 at 02:12
  • Does this answer your question? [Duplicate AssemblyVersion Attribute](https://stackoverflow.com/questions/10311347/duplicate-assemblyversion-attribute) – Lex Li Jan 03 '20 at 06:18
  • 1
    @IanKemp, are your sure that deleting the files should help? The files are in the `obj` folder. And afaik the folder will be recreated after every build. Should I write a script to remove the files then? The files were created due to the projects creation. I create each separate project with the help of the `dotnet new classlib`, since I need only the functionality from those projects which will be exploited by my main project. Should I create different kinds of projects for my case (not the `classlib`)? – qqqqqqq Jan 03 '20 at 19:08
  • @JaliyaUdagedara, it is a pity but that did not help. I tried it as one of the first resorts. – qqqqqqq Jan 03 '20 at 19:10
  • @LexLi, the topic starter in the question referred asks why one of the solutions (described in the linked MS article in the question) helps. My question is not about why, my question is about other approaches to fix this because all the approaches I found do not help. Also I have a strong feeling that in my case I miss something trivial and important simultaneously, so I hope that maybe someone who faced the same (or similar) issue will be able to help me. – qqqqqqq Jan 03 '20 at 19:13
  • 1) Stop using comments to hold details, and always edit your question to reflect the latest. 2) That linked thread provided so many options, so if you believe none of them helps you need to say why they "do not help". – Lex Li Jan 03 '20 at 19:55
  • @LexLi, I agree with you. Thank you for your time. Hope I will become better at being a part of the SO community. – qqqqqqq Jan 03 '20 at 21:07
  • @LexLi, should I remove all my comments above? – qqqqqqq Jan 03 '20 at 21:07
  • I cannot reproduce those errors once those MSBuild properties are set to false. Another mistake in that project file is that `netstandard3.0` doesn't exist yet. You can only go to at most 2.1. – Lex Li Jan 03 '20 at 22:45
  • @LexLi, that is strange. The `netstandard3.0` is auto-generated target version. Your last comment is appropriate as an answer from my pov. Or should I remove the question? – qqqqqqq Jan 07 '20 at 23:25
  • @LexLi, thank you a lot for the help. – qqqqqqq Jan 07 '20 at 23:25
  • Before saying I am wrong, learn the differences between netcoreapp30 and netstandard30. Thanks. – Lex Li Jan 08 '20 at 21:19
  • @LexLi, I am sorry. Thank you. – qqqqqqq Jan 08 '20 at 21:55

5 Answers5

10

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>
John Irvine
  • 156
  • 2
  • 7
2

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
Lars Passic
  • 163
  • 2
  • 8
1

For .NET 6 I deleted the .vs folder, cleaned and did a Build on the project and the errors were resolved.

enter image description here

0

I experienced this issue when we moved the projects to a new folder (in this case one level higher), but our repo still had the projects in their old locations as well, so it found the duplicate. My key was to clear out the old projects (this was Jenkins so I wiped the workspace) and rebuild.

Mike
  • 629
  • 5
  • 18
0

Solved the Error CS0579 - error because of class library reference (dotnet5.0)

Error CS0579: Duplicate 'global::System.Runtime.Versioning.TargetFrameworkAttribute' attribute (CS0579)

Error CS0579: Duplicate 'System.Reflection.AssemblyCompanyAttribute' attribute (CS0579)

If you get this error, it's because it create the files twice once in the class library and once in the referenced project. Go in the referenced project to: “NameOfTheClassLibrary” —> obj —> Debug —> net5.0 —> ref —> here delete the files that are mentioned in the error stack (for me: AssemblyInfo.cs & .NETCore...AssemblyAttributes.cs)

(Visual Studio access ClassLibrary.csproj file): Open the ClassLibrary.csproj —> by right clicking —> unload —> right click again —> tool —> Edit file

Add TargetFramework, GenerateAssemblyInfo, GenerateTargetFrameworkAttribute to the file to prevent the compiler from creating this files in the referenced project.

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

  <PropertyGroup>
    <OutputType>Library</OutputType>
    <TargetFramework>net5.0</TargetFramework>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    <GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
  </PropertyGroup>

</Project>

Save the file a recompile.