Ошибка cs0579 повторяющийся атрибут global system runtime versioning targetframeworkattribute

When I build my application I get the following error

 Error  CS0579  Duplicate 'global::System.Runtime.Versioning.TargetFrameworkAttribute' attribute    MyUIApp
D:MyUIAppobjDebugnetcoreapp3.1.NETCoreApp,Version=v3.1.AssemblyAttributes.cs   4   Active

The following code is autogenerated in the obj/Debug/netcoreapp3.1 folder

//
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(«.NETCoreApp,Version=v3.1», FrameworkDisplayName = «»)]

I have a project file starting with

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <OutputType>Library</OutputType>
    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..</SolutionDir>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    <RestorePackages>true</RestorePackages>
    <UseWindowsForms>true</UseWindowsForms>
  </PropertyGroup>
  <PropertyGroup>

I can work around the issue by commenting out the contents of the file, but not by deleting the file.

asked May 25, 2020 at 7:45

Kirsten's user avatar

KirstenKirsten

15.1k39 gold badges175 silver badges309 bronze badges

1

I was also getting this error in VS Code and the following fixed it.

I have a project/solution with three projects within in.

  • netstandard2.1
  • netstandard2.1
  • netcoreapp3.1

I added the following line to each of the *.csproj files within the <PropertyGroup> section:

<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>

Full example

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

  <PropertyGroup>
    <TargetFramework>netstandard2.1</TargetFramework>
    <GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
  </PropertyGroup>

</Project>

After doing the above you might need to clean /bin and /obj folders for each project.

This article pointed me in the right direction though nothing online that I found mentioned the attribute above. I just guessed and it worked!

Mauricio Gracia Gutierrez's user avatar

answered Jun 18, 2020 at 16:51

wsamoht's user avatar

wsamohtwsamoht

1,5681 gold badge12 silver badges14 bronze badges

6

Add the following two lines to the <PropertyGroup>. This fixed it for me.

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

Jonathan Allen's user avatar

answered Sep 11, 2020 at 19:53

Chuck Hardt's user avatar

Chuck HardtChuck Hardt

1,0821 gold badge5 silver badges3 bronze badges

5

The problem was about my folder structure : the test project was in the main project folder. Passing each side by side in the same repo solved the problem

MyProject
   src/MyProject.csproj
   tests/MyTestProject.csproj

Taken from Github issue : https://github.com/dotnet/core/issues/4837

Mauricio Gracia Gutierrez's user avatar

answered Jun 17, 2020 at 10:02

Cladoo's user avatar

CladooCladoo

6786 silver badges20 bronze badges

8

So i did encounter the same on a .NET 4.7 based solution, spent hours, only to find out a colleague of mine did include the obj and bin folders in the project!
excluding them fixed the issue and that error went away.

hope this save someone a couple of hours.

answered Dec 3, 2021 at 18:18

azaki's user avatar

azakiazaki

4565 silver badges5 bronze badges

5

I fixed this by deleting the obj and bin folders in each project directory. I then cleaned the solution and rebuilt. The rebuild succeeded.

answered Oct 7, 2020 at 1:15

Kevin McCaffery's user avatar

3

You just need to exclude the obj folder from the project/solution.

answered Aug 4, 2021 at 17:26

Joe Shakely's user avatar

Joe ShakelyJoe Shakely

5636 silver badges9 bronze badges

5

Try to delete obj folder from Project, delete it from SolutionExplorer instead of WindowExplorer.

answered May 12, 2022 at 2:34

mtu.nguyen305's user avatar

2

I was facing the same issue in my asp.net core 3.1 application right after I add the xUnit project to the solution. Ultimately, the main issue was because of that I selected the check box Place solution and project in the same directory as shown in the preceding image.

enter image description here

This should work in normal cases, and you will just consider this root directory as the Git repository (the .sln file and the .csproj will be in the same folder). But you will not be able to add a new project to this directory as you will get the error «Error CS0579 Duplicate ‘global::System.Runtime.Versioning.TargetFrameworkAttribute'». So, to fix this error, we just have to follow the preceding steps.

  1. Create a folder with the same name in the .sln file
  2. Move all the project-related files to that directory
  3. Open your .sln file with any code editor
  4. Edit the Project references.
  5. Make sure that your .sln file is in the root directory

This is how your project file references may look like now.

Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApplication2", "WebApplication2WebApplication2.csproj", "{027937D8-D0E6-45A4-8846-C2E28DA102E6}"
EndProject 

Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApplication2.Tests", "WebApplication2.TestsWebApplication2.Tests.csproj", "{AD4C6C31-F617-4E76-985A-32B0E3104004}" 
EndProject

That’s it. Just reload your solution and happy coding!.

answered Nov 19, 2020 at 12:15

Sibeesh Venu's user avatar

Sibeesh VenuSibeesh Venu

17.8k12 gold badges99 silver badges138 bronze badges

0

I encountered that issue, what I did is I deleted the .NETCoreApp,Version=v3.1.AssemblyAttributes.cs and then I ran VSCode as an administrator.

answered May 28, 2020 at 8:27

Stephen Melben Corral's user avatar

I had this when my folder structure got messed up. I’m using Visual Studio 2019 and switched branches that has different folder structure. Some folders got added up in the file explorer and didn’t get deleted even if I switched branches. All I did was to delete those folders that weren’t part of my current branch and it worked.

answered Mar 27, 2021 at 0:43

Raffy's user avatar

RaffyRaffy

4751 gold badge8 silver badges12 bronze badges

1

I am having the same problem. As far as I can tell, the flag should prevent the auto-generation of assembly info. However, I can see this file in my obj directory:

.NETStandard,Version=v2.1.AssemblyAttributes.cs

It only contains the target version attribute. Maybe there is some other way of suppressing this attribute?

It seems like this might be a regression in .NET core 3.1.300. I was building with .NET core 3.1.200 and I didn’t see this issue until I upgraded.

answered May 26, 2020 at 11:57

Steve Haddon's user avatar

2

I experienced this on a build pipeline in Azure Devops. I was using a local agent to run the pipeline on (my own machine). It appears that there was code in the working directory that was causing this conflict, and by default, the agent doesn’t clean the working directory before starting the pipeline process.

The fix was to delete the contents of the working directory on the agent. I did this by selecting the option to clean the working directory:

Clean the working directory in Azure Devops get sources page

answered Aug 31, 2020 at 21:13

ajbeaven's user avatar

ajbeavenajbeaven

9,20513 gold badges75 silver badges120 bronze badges

I had this kind of Errors in my Blazor Server project when I tried to add .NET Standard Class Library project in Visual Studio 2019.

Errors:

Errors

To fix this i tried following ways.

.csproj file Before

Before

.csproj file After

Solution

answered Sep 30, 2021 at 18:31

Shivkumar Nagre's user avatar

1

In my case the culprit was my test project so I had to go to my test folder > obj > Debug/net6.0 > .NETCoreApp,Version=v6.0.AssemblyAttributes.cs

and then commented this line

[assembly:global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]

answered Jul 15, 2022 at 10:22

Sven.hig's user avatar

Sven.higSven.hig

4,4602 gold badges7 silver badges18 bronze badges

This error can also happen if you accidentally copied an project file into another projects folder.

answered Dec 18, 2020 at 6:44

Johan's user avatar

JohanJohan

1652 silver badges2 bronze badges

in my case (.NET 6.0);
I just exclude the Properties folder from the project/solution.

answered Apr 16, 2022 at 8:18

AminRostami's user avatar

AminRostamiAminRostami

2,5353 gold badges28 silver badges45 bronze badges

From the many different kind of answers, it’s clear that there could be different reasons for the same issue. In my case the solution definition file was the cause. I decided to delete and create a clean solution file.

  1. Delete the .sln file
  2. Create a blank .sln file, in the root of your project/solution:
dotnet new sln
  1. For every C# project file in your solution, add it with the following command, for example:
dotnet add MyApplication.csproj

and for example:

dotnet add CustomPackages/MyLibrary.csproj

Then to make sure all previous build artefacts are cleaned up

dotnet clean

answered May 24, 2022 at 13:51

Superman.Lopez's user avatar

Superman.LopezSuperman.Lopez

1,1762 gold badges10 silver badges38 bronze badges

Encountered this issue when working with AWS Lambda. Turns out I was switching branches, and some auto-generated folders did not get cleared after switching to new branch, and dotnet was picking them up for some reason. The easiest solution is to delete all local project folders, and check out clean version of the code again.

answered Jan 4 at 18:18

Eternal21's user avatar

Eternal21Eternal21

4,0702 gold badges47 silver badges61 bronze badges

I would like to mention a different case here which causes the issue because nothing from the solutions worked in my case.
When I clicked on the error, it took me to a file. This file was inside a folder, which was mistakenly moved from another project. I reverted it back to original position and it fixed the issue.

answered May 4 at 2:46

Charlie's user avatar

CharlieCharlie

4,8092 gold badges31 silver badges55 bronze badges

I commented out the offending attribute

// obj/Debug/netcoreapp3.1/.NETCoreApp,Version=v3.1.AssemblyAttributes.cs

using System;
using System.Reflection;
//[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v3.1", FrameworkDisplayName = "")]

answered Aug 6, 2020 at 14:55

Geoff Langenderfer's user avatar

1

DELETE [assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]

enter image description here

Suraj Rao's user avatar

Suraj Rao

29.3k11 gold badges94 silver badges103 bronze badges

answered Sep 2, 2022 at 12:09

An Phú's user avatar

I was able to solve this issue by getting a new clone of the project.

answered Apr 28, 2021 at 5:08

Ahamed Ishak's user avatar

Hello, I am working on a SDK where we have multiple build targets. I have been running into an issue where each of the targets seems to be building assembly attributes when I have explicitly turned them off with

<TargetFramework>netstandard2.0</TargetFramework> <GeneratePackageOnBuild>true</GeneratePackageOnBuild> <AssemblyName>Dropbox.Api</AssemblyName> <RootNamespace>Dropbox.Api</RootNamespace> <GenerateAssemblyInfo>false</GenerateAssemblyInfo> <GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> <GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute> <GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute> <GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> <GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute> <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> <GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>

In the main property group of every csproj file

Here is the errors I am seeing:

net45objDebug.NETFramework,Version=v4.5.AssemblyAttributes.cs(4,12): error CS0579: Duplicate 'global::System.Runtime. Versioning.TargetFrameworkAttribute' attribute [dropbox-sdk-dotnetdropbox-sdk-dotnetDropbox.Api Dropbox.Api.NetStandard.csproj] net45objRelease.NETFramework,Version=v4.5.AssemblyAttributes.cs(4,12): error CS0579: Duplicate 'global::System.Runtim e.Versioning.TargetFrameworkAttribute' attribute [dropbox-sdk-dotnetdropbox-sdk-dotnetDropbox.Ap iDropbox.Api.NetStandard.csproj] portable40objDebug.NETPortable,Version=v4.0,Profile=Profile344.AssemblyAttributes.cs(4,12): error CS0579: Duplicate ' global::System.Runtime.Versioning.TargetFrameworkAttribute' attribute [dropbox-sdk-dotnetdropbox- sdk-dotnetDropbox.ApiDropbox.Api.NetStandard.csproj] portable40objRelease.NETPortable,Version=v4.0,Profile=Profile344.AssemblyAttributes.cs(4,12): error CS0579: Duplicate 'global::System.Runtime.Versioning.TargetFrameworkAttribute' attribute [dropbox-sdk-dotnetdropbo x-sdk-dotnetDropbox.ApiDropbox.Api.NetStandard.csproj] portableobjDebug.NETPortable,Version=v4.5,Profile=Profile111.AssemblyAttributes.cs(4,12): error CS0579: Duplicate 'gl obal::System.Runtime.Versioning.TargetFrameworkAttribute' attribute [dropbox-sdk-dotnetdropbox-sd k-dotnetDropbox.ApiDropbox.Api.NetStandard.csproj] portableobjRelease.NETPortable,Version=v4.5,Profile=Profile111.AssemblyAttributes.cs(4,12): error CS0579: Duplicate ' global::System.Runtime.Versioning.TargetFrameworkAttribute' attribute [dropbox-sdk-dotnetdropbox- sdk-dotnetDropbox.ApiDropbox.Api.NetStandard.csproj] objReleasenetstandard2.0.NETStandard,Version=v2.0.AssemblyAttributes.cs(4,12): error CS0579: Duplicate 'global::Syst em.Runtime.Versioning.TargetFrameworkAttribute' attribute [dropbox-sdk-dotnetdropbox-sdk-dotnetD ropbox.ApiDropbox.Api.NetStandard.csproj]

I am not sure if I am generating this incorrectly or if there is another way to disable this error.
For more information, I am working on the Dropbox SDK

I got the following errors today while working on a new project:

Error CS0579 Duplicate ‘System.Reflection.AssemblyVersionAttribute’ attribute MyAzureFunction C:ReposTestMyAzureFunctionobjDebugnet6.0MyAzureFunction.AssemblyInfo.cs 20 Active

Error CS0579 Duplicate ‘global::System.Runtime.Versioning.TargetFrameworkAttribute’ attribute MyAzureFunction C:ReposTestMyAzureFunctionobjDebugnet6.0.NETCoreApp,Version=v6.0.AssemblyAttributes.cs 4 Active

Error CS0579 Duplicate ‘System.Reflection.AssemblyCompanyAttribute’ attribute MyAzureFunction C:ReposTestMyAzureFunctionobjDebugnet6.0MyAzureFunction.AssemblyInfo.cs 14 Active

Error CS0579 Duplicate ‘System.Reflection.AssemblyConfigurationAttribute’ attribute MyAzureFunction C:ReposTestMyAzureFunctionobjDebugnet6.0MyAzureFunction.AssemblyInfo.cs 15 Active

Error CS0579 Duplicate ‘System.Reflection.AssemblyFileVersionAttribute’ attribute MyAzureFunction C:ReposTestMyAzureFunctionobjDebugnet6.0MyAzureFunction.AssemblyInfo.cs 16 Active

Error CS0579 Duplicate ‘System.Reflection.AssemblyInformationalVersionAttribute’ attribute MyAzureFunction C:ReposTestMyAzureFunctionobjDebugnet6.0MyAzureFunction.AssemblyInfo.cs 17 Active

Error CS0579 Duplicate ‘System.Reflection.AssemblyProductAttribute’ attribute MyAzureFunction C:ReposTestMyAzureFunctionobjDebugnet6.0MyAzureFunction.AssemblyInfo.cs 18 Active

Error CS0579 Duplicate ‘System.Reflection.AssemblyTitleAttribute’ attribute MyAzureFunction C:ReposTestMyAzureFunctionobjDebugnet6.0MyAzureFunction.AssemblyInfo.cs 19 Active

and it looked like the following in the error list:

duplicate-attribute-build-error

I figured out that I had created a project within my project by mistake. I had two projects «MyAzureFunction» and «YahooFinanceApi». The project structure looked like the following:

BaseFolder
   MyAzureFunction
      MyAzureFunction.csproj
      YahooFinanceApi
         YahooFinanceApi.Csjproj
      solution.sln

What solved the above for me was changing the above to the following:

BaseFolder
   MyAzureFunction
      MyAzureFunction.csproj
   YahooFinanceApi
      YahooFinanceApi.csproj
   solution.sln

This way the YahooFinanceApi project was not built within the MyAzureFunction project. For some reason this made the MyAzureFunction project fail with the duplicate error when built.

I hope this helps someone out there :)

Hello, I am working on a SDK where we have multiple build targets. I have been running into an issue where each of the targets seems to be building assembly attributes when I have explicitly turned them off with

<TargetFramework>netstandard2.0</TargetFramework> <GeneratePackageOnBuild>true</GeneratePackageOnBuild> <AssemblyName>Dropbox.Api</AssemblyName> <RootNamespace>Dropbox.Api</RootNamespace> <GenerateAssemblyInfo>false</GenerateAssemblyInfo> <GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> <GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute> <GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute> <GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> <GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute> <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> <GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>

In the main property group of every csproj file

Here is the errors I am seeing:

net45objDebug.NETFramework,Version=v4.5.AssemblyAttributes.cs(4,12): error CS0579: Duplicate 'global::System.Runtime. Versioning.TargetFrameworkAttribute' attribute [dropbox-sdk-dotnetdropbox-sdk-dotnetDropbox.Api Dropbox.Api.NetStandard.csproj] net45objRelease.NETFramework,Version=v4.5.AssemblyAttributes.cs(4,12): error CS0579: Duplicate 'global::System.Runtim e.Versioning.TargetFrameworkAttribute' attribute [dropbox-sdk-dotnetdropbox-sdk-dotnetDropbox.Ap iDropbox.Api.NetStandard.csproj] portable40objDebug.NETPortable,Version=v4.0,Profile=Profile344.AssemblyAttributes.cs(4,12): error CS0579: Duplicate ' global::System.Runtime.Versioning.TargetFrameworkAttribute' attribute [dropbox-sdk-dotnetdropbox- sdk-dotnetDropbox.ApiDropbox.Api.NetStandard.csproj] portable40objRelease.NETPortable,Version=v4.0,Profile=Profile344.AssemblyAttributes.cs(4,12): error CS0579: Duplicate 'global::System.Runtime.Versioning.TargetFrameworkAttribute' attribute [dropbox-sdk-dotnetdropbo x-sdk-dotnetDropbox.ApiDropbox.Api.NetStandard.csproj] portableobjDebug.NETPortable,Version=v4.5,Profile=Profile111.AssemblyAttributes.cs(4,12): error CS0579: Duplicate 'gl obal::System.Runtime.Versioning.TargetFrameworkAttribute' attribute [dropbox-sdk-dotnetdropbox-sd k-dotnetDropbox.ApiDropbox.Api.NetStandard.csproj] portableobjRelease.NETPortable,Version=v4.5,Profile=Profile111.AssemblyAttributes.cs(4,12): error CS0579: Duplicate ' global::System.Runtime.Versioning.TargetFrameworkAttribute' attribute [dropbox-sdk-dotnetdropbox- sdk-dotnetDropbox.ApiDropbox.Api.NetStandard.csproj] objReleasenetstandard2.0.NETStandard,Version=v2.0.AssemblyAttributes.cs(4,12): error CS0579: Duplicate 'global::Syst em.Runtime.Versioning.TargetFrameworkAttribute' attribute [dropbox-sdk-dotnetdropbox-sdk-dotnetD ropbox.ApiDropbox.Api.NetStandard.csproj]

I am not sure if I am generating this incorrectly or if there is another way to disable this error.
For more information, I am working on the Dropbox SDK

Содержание

  1. Duplicate Targetframework attribute #9781
  2. Comments
  3. Steps to reproduce
  4. Expected behavior
  5. Actual behavior
  6. Environment data
  7. CS0579 Duplicate Attribute Error with .NET Core
  8. Problem description
  9. tl;dr Solution
  10. Details
  11. error CS0579: Duplicate ‘global::System.Runtime.Versioning.TargetFrameworkAttribute’ attribute #12297
  12. Comments
  13. Ошибка CS0579: дубликат global::System.Runtime.Versioning.TargetFrameworkAttribute
  14. 18 ответов
  15. dotnet build results in error CS0579 duplicate attributes with AssemblyVersionAttribute (and others) specified #7207
  16. Comments
  17. Steps to reproduce
  18. Expected behavior
  19. Actual behavior
  20. Environment data

Duplicate Targetframework attribute #9781

I have similary problems with that issue.
It started when i run npm install . Packages installation finished with error then dotnet build got error
I tried deleting the obj and use dotnet clean . It is not helped me.

Steps to reproduce

Expected behavior

Actual behavior

Environment data

dotnet —info output:

The text was updated successfully, but these errors were encountered:

Please, provide us with more details. What kind of project are you creating? Can you give us a full repro for this? The issue you referenced has been closed for months. Please provide either a repo on github where we can repro this or detailed repro steps. The steps you provided above are not sufficient.

My project very old. The project was successfully compiled before use npm install .
I notice that in project root folder create autogenerate file .NETCoreApp,Version=v2.1.AssemblyAttributes.cs . If I delete it the compilation is successful but then created again

I am not sure why npm install would interfere with this at all. Do you have any customization in your project that might be causing this?

Could you share with us a binlog? dotnet build /bl, should generate a .binlog file that you could share with us. Do notice that if you do, the binlog logs secrets and things like that, so make sure you don’t have any in your build before sharing.

Without a binlog or a repro we can reproduce ourselves, there isn’t much we can do.

You can try setting false in your project, so see if the file stops being generated and your build succeeds.

No, i think that no. Before the advent of have this error i added one new npm package in my project.

Okay, can I leave a direct link here?

Without a binlog or a repro we can reproduce ourselves, there isn’t much we can do.

Yes, this help me

You can try setting false in your project, so see if the file stops being generated and your build succeeds.

Yes, you can leave a link here.

So, setting the property above fixed the issue for you?

Источник

CS0579 Duplicate Attribute Error with .NET Core

I’ll leave the below for posterity, but recently I came across the real reason for the error. In this issue it was pointed out that your .net core solutions have to be structured in a particular way. Specifically, make sure that you do not create projects in the same directory as your main project.

Problem description

I recently started working on my first .NET Core project and quickly ran into a problem. After adding a class library project, the second time I ran dotnet run I received the following errors:

error CS0579: Duplicate ‘System.Reflection.AssemblyCompanyAttribute’ attribute error CS0579: Duplicate ‘System.Reflection.AssemblyConfigurationAttribute’ attribute error CS0579: Duplicate ‘System.Reflection.AssemblyFileVersionAttribute’ attribute error CS0579: Duplicate ‘System.Reflection.AssemblyInformationalVersionAttribute’ attribute error CS0579: Duplicate ‘System.Reflection.AssemblyProductAttribute’ attribute error CS0579: Duplicate ‘System.Reflection.AssemblyTitleAttribute’ attribute error CS0579: Duplicate ‘System.Reflection.AssemblyVersionAttribute’ attribute

tl;dr Solution

My Google-fu revealed the solution buried in a GitHub issue thread. Add the following line to your *.csproj files:

As the name indicates, this will prevent the build process from generating the AssemblyInfo.cs file in project obj directories, thus preventing the duplicate attribute conflict.

Details

Disclaimer: I am far from a .NET expert so there is probably more to this story.

Источник

Hello, I am working on a SDK where we have multiple build targets. I have been running into an issue where each of the targets seems to be building assembly attributes when I have explicitly turned them off with

In the main property group of every csproj file

Here is the errors I am seeing:

net45objDebug.NETFramework,Version=v4.5.AssemblyAttributes.cs(4,12): error CS0579: Duplicate ‘global::System.Runtime. Versioning.TargetFrameworkAttribute’ attribute [dropbox-sdk-dotnetdropbox-sdk-dotnetDropbox.Api Dropbox.Api.NetStandard.csproj] net45objRelease.NETFramework,Version=v4.5.AssemblyAttributes.cs(4,12): error CS0579: Duplicate ‘global::System.Runtim e.Versioning.TargetFrameworkAttribute’ attribute [dropbox-sdk-dotnetdropbox-sdk-dotnetDropbox.Ap iDropbox.Api.NetStandard.csproj] portable40objDebug.NETPortable,Version=v4.0,Profile=Profile344.AssemblyAttributes.cs(4,12): error CS0579: Duplicate ‘ global::System.Runtime.Versioning.TargetFrameworkAttribute’ attribute [dropbox-sdk-dotnetdropbox- sdk-dotnetDropbox.ApiDropbox.Api.NetStandard.csproj] portable40objRelease.NETPortable,Version=v4.0,Profile=Profile344.AssemblyAttributes.cs(4,12): error CS0579: Duplicate ‘global::System.Runtime.Versioning.TargetFrameworkAttribute’ attribute [dropbox-sdk-dotnetdropbo x-sdk-dotnetDropbox.ApiDropbox.Api.NetStandard.csproj] portableobjDebug.NETPortable,Version=v4.5,Profile=Profile111.AssemblyAttributes.cs(4,12): error CS0579: Duplicate ‘gl obal::System.Runtime.Versioning.TargetFrameworkAttribute’ attribute [dropbox-sdk-dotnetdropbox-sd k-dotnetDropbox.ApiDropbox.Api.NetStandard.csproj] portableobjRelease.NETPortable,Version=v4.5,Profile=Profile111.AssemblyAttributes.cs(4,12): error CS0579: Duplicate ‘ global::System.Runtime.Versioning.TargetFrameworkAttribute’ attribute [dropbox-sdk-dotnetdropbox- sdk-dotnetDropbox.ApiDropbox.Api.NetStandard.csproj] objReleasenetstandard2.0.NETStandard,Version=v2.0.AssemblyAttributes.cs(4,12): error CS0579: Duplicate ‘global::Syst em.Runtime.Versioning.TargetFrameworkAttribute’ attribute [dropbox-sdk-dotnetdropbox-sdk-dotnetD ropbox.ApiDropbox.Api.NetStandard.csproj]

I am not sure if I am generating this incorrectly or if there is another way to disable this error.
For more information, I am working on the Dropbox SDK

The text was updated successfully, but these errors were encountered:

Источник

Ошибка CS0579: дубликат global::System.Runtime.Versioning.TargetFrameworkAttribute

Когда я создаю свое приложение, я получаю следующую ошибку

Следующий код автоматически создается в папке obj/Debug/netcoreapp3.1.

// используя System; using System.Reflection; [сборка: global::System.Runtime.Versioning.TargetFrameworkAttribute(«.NETCoreApp,Version=v3.1», FrameworkDisplayName = «»)]

У меня есть файл проекта, начинающийся с

Я могу обойти проблему, закомментировав содержимое файла, но не удалив файл.

18 ответов

Я также получал эту ошибку в VS Code, и следующее исправило ее.

У меня есть проект / решение с тремя проектами внутри.

  • netstandard2.1
  • netstandard2.1
  • netcoreapp3.1

Я добавил следующую строку к каждому из *.csproj файлы:

Эта статья указала мне в правильном направлении, хотя в Интернете ничего не упоминалось об этом атрибуте. Я просто догадался, и это сработало!

Добавьте следующие две строки в

. Это исправило это для меня.

Я решил проблему способом, описанным в проблеме Github: https://github.com/dotnet/core/issues/4837

Проблема заключалась в структуре моей папки: тестовый проект находился в основной папке проекта. Передача каждого бок о бок в одном репо решила проблему

Так что я столкнулся с тем же самым в решении на основе .NET 4.7, потратил часы, только чтобы узнать, что мой коллега действительно включил папки obj и bin в проект! их исключение устранило проблему, и эта ошибка исчезла.

надеюсь, это сэкономит кому-то пару часов.

Я исправил это, удалив папки obj и bin в каждом каталоге проекта. Затем я очистил раствор и восстановил. Восстановление выполнено успешно.

Вам просто нужно исключить obj папку из проекта / решения.

Я столкнулся с той же проблемой в моем asp.net core 3.1 приложение сразу после добавления xUnit проект к решению. В конечном итоге основная проблема заключалась в том, что я установил флажок Поместить решение и проект в тот же каталог, что и на предыдущем изображении.

Это должно работать в обычных случаях, и вы просто будете рассматривать этот корневой каталог как репозиторий Git ( .sln файл и .csproj будет в той же папке). Но вы не сможете добавить новый проект в этот каталог, так как вы получите ошибку «Ошибка CS0579 Duplicate ‘global::System.Runtime.Versioning.TargetFrameworkAttribute’». Итак, чтобы исправить эту ошибку, нам просто нужно выполнить предыдущие шаги.

  1. Создайте папку с таким же именем в .sln файл
  2. Переместите все файлы, связанные с проектом, в этот каталог
  3. Откройте свой .sln файл любым редактором кода
  4. Отредактируйте ссылки на проект.
  5. Убедитесь, что ваш .sln файл находится в корневом каталоге

Вот как теперь могут выглядеть ссылки на файлы вашего проекта.

Вот и все. Просто перезагрузите свое решение и удачного кодирования!.

Источник

dotnet build results in error CS0579 duplicate attributes with AssemblyVersionAttribute (and others) specified #7207

Building a library project fails with error CS0579 (duplicate attribute) with library projects with AssemblyVersionAttribute (or other assembly attributes) specified.

  • Adding (for example) false to csproj fixes

Steps to reproduce

  • dotnet new -t lib
  • insert [assembly: System.Reflection.AssemblyVersion(«0.1.0.0»)] into Library.cs
  • dotnet restore
  • dotnet build

Expected behavior

Build is successful

Actual behavior

Environment data

The text was updated successfully, but these errors were encountered:

Setting GenerateAssemblyInfo property to false fixes for all attributes:

@frankbuckley Im glad the switches fix the issue. Do you have thoughts on how the experience should change?

(I’m not sure why I thought this did not happen with exe projects. I have just tried again and it does.)

I hit the issue porting existing code from existing PCL projects by creating a new netstandard/core library ( dotnet new -t lib ) and copying sources (including, as it happened, PropertiesAssemblyInfo.cs).

If traditional assembly attributes are being somehow deprecated in the new csproj model, I think the error message should be more explanatory. I was left wondering «what duplicates?» The error message should state something like assembly attributes are generated from the project file, hence the duplication.

That said, if assembly attributes are defined in code files, could they not simply take precedence and prevent the (duplicated) generation of assembly attributes by the build system?

It is particular confusing that these are auto-generated when there are no properties in the csproj file specifying version numbers (or company, etc.) They seem to appear from nowhere!

Источник

I got the following errors today while working on a new project:

Error CS0579 Duplicate ‘System.Reflection.AssemblyVersionAttribute’ attribute MyAzureFunction C:ReposTestMyAzureFunctionobjDebugnet6.0MyAzureFunction.AssemblyInfo.cs 20 Active

Error CS0579 Duplicate ‘global::System.Runtime.Versioning.TargetFrameworkAttribute’ attribute MyAzureFunction C:ReposTestMyAzureFunctionobjDebugnet6.0.NETCoreApp,Version=v6.0.AssemblyAttributes.cs 4 Active

Error CS0579 Duplicate ‘System.Reflection.AssemblyCompanyAttribute’ attribute MyAzureFunction C:ReposTestMyAzureFunctionobjDebugnet6.0MyAzureFunction.AssemblyInfo.cs 14 Active

Error CS0579 Duplicate ‘System.Reflection.AssemblyConfigurationAttribute’ attribute MyAzureFunction C:ReposTestMyAzureFunctionobjDebugnet6.0MyAzureFunction.AssemblyInfo.cs 15 Active

Error CS0579 Duplicate ‘System.Reflection.AssemblyFileVersionAttribute’ attribute MyAzureFunction C:ReposTestMyAzureFunctionobjDebugnet6.0MyAzureFunction.AssemblyInfo.cs 16 Active

Error CS0579 Duplicate ‘System.Reflection.AssemblyInformationalVersionAttribute’ attribute MyAzureFunction C:ReposTestMyAzureFunctionobjDebugnet6.0MyAzureFunction.AssemblyInfo.cs 17 Active

Error CS0579 Duplicate ‘System.Reflection.AssemblyProductAttribute’ attribute MyAzureFunction C:ReposTestMyAzureFunctionobjDebugnet6.0MyAzureFunction.AssemblyInfo.cs 18 Active

Error CS0579 Duplicate ‘System.Reflection.AssemblyTitleAttribute’ attribute MyAzureFunction C:ReposTestMyAzureFunctionobjDebugnet6.0MyAzureFunction.AssemblyInfo.cs 19 Active

and it looked like the following in the error list:

duplicate-attribute-build-error

I figured out that I had created a project within my project by mistake. I had two projects «MyAzureFunction» and «YahooFinanceApi». The project structure looked like the following:

BaseFolder
   MyAzureFunction
      MyAzureFunction.csproj
      YahooFinanceApi
         YahooFinanceApi.Csjproj
      solution.sln

What solved the above for me was changing the above to the following:

BaseFolder
   MyAzureFunction
      MyAzureFunction.csproj
   YahooFinanceApi
      YahooFinanceApi.csproj
   solution.sln

This way the YahooFinanceApi project was not built within the MyAzureFunction project. For some reason this made the MyAzureFunction project fail with the duplicate error when built.

I hope this helps someone out there :)

When I build my application I get the following error

 Error  CS0579  Duplicate 'global::System.Runtime.Versioning.TargetFrameworkAttribute' attribute    MyUIApp
D:MyUIAppobjDebugnetcoreapp3.1.NETCoreApp,Version=v3.1.AssemblyAttributes.cs   4   Active

The following code is autogenerated in the obj/Debug/netcoreapp3.1 folder

//
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(«.NETCoreApp,Version=v3.1», FrameworkDisplayName = «»)]

I have a project file starting with

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <OutputType>Library</OutputType>
    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..</SolutionDir>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    <RestorePackages>true</RestorePackages>
    <UseWindowsForms>true</UseWindowsForms>
  </PropertyGroup>
  <PropertyGroup>

I can work around the issue by commenting out the contents of the file, but not by deleting the file.

15 Answers

I was also getting this error in VS Code and the following fixed it.

I have a project/solution with three projects within in.

  • netstandard2.1
  • netstandard2.1
  • netcoreapp3.1

I added the following line to each of the *.csproj files within the <PropertyGroup> section:

<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>

Full example

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

  <PropertyGroup>
    <TargetFramework>netstandard2.1</TargetFramework>
    <GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
  </PropertyGroup>

</Project>

After doing the above you might need to clean /bin and /obj folders for each project.

This article pointed me in the right direction though nothing online that I found mentioned the attribute above. I just guessed and it worked!

Add the following two lines to the <PropertyGroup>. This fixed it for me.

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

The problem was about my folder structure : the test project was in the main project folder. Passing each side by side in the same repo solved the problem

MyProject
   src/MyProject.csproj
   tests/MyTestProject.csproj

Taken from Github issue : https://github.com/dotnet/core/issues/4837

I fixed this by deleting the obj and bin folders in each project directory. I then cleaned the solution and rebuilt. The rebuild succeeded.

You just need to exclude the obj folder from the project/solution.

I was facing the same issue in my asp.net core 3.1 application right after I add the xUnit project to the solution. Ultimately, the main issue was because of that I selected the check box Place solution and project in the same directory as shown in the preceding image.

enter image description here

This should work in normal cases, and you will just consider this root directory as the Git repository (the .sln file and the .csproj will be in the same folder). But you will not be able to add a new project to this directory as you will get the error «Error CS0579 Duplicate ‘global::System.Runtime.Versioning.TargetFrameworkAttribute’». So, to fix this error, we just have to follow the preceding steps.

  1. Create a folder with the same name in the .sln file
  2. Move all the project-related files to that directory
  3. Open your .sln file with any code editor
  4. Edit the Project references.
  5. Make sure that your .sln file is in the root directory

This is how your project file references may look like now.

Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApplication2", "WebApplication2WebApplication2.csproj", "{027937D8-D0E6-45A4-8846-C2E28DA102E6}"
EndProject 

Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApplication2.Tests", "WebApplication2.TestsWebApplication2.Tests.csproj", "{AD4C6C31-F617-4E76-985A-32B0E3104004}" 
EndProject

That’s it. Just reload your solution and happy coding!.

I encountered that issue, what I did is I deleted the .NETCoreApp,Version=v3.1.AssemblyAttributes.cs and then I ran VSCode as an administrator.

So i did encounter the same on a .NET 4.7 based solution, spent hours, only to find out a colleague of mine did include the obj and bin folders in the project!
excluding them fixed the issue and that error went away.

hope this save someone a couple of hours.

I am having the same problem. As far as I can tell, the flag should prevent the auto-generation of assembly info. However, I can see this file in my obj directory:

.NETStandard,Version=v2.1.AssemblyAttributes.cs

It only contains the target version attribute. Maybe there is some other way of suppressing this attribute?

It seems like this might be a regression in .NET core 3.1.300. I was building with .NET core 3.1.200 and I didn’t see this issue until I upgraded.

I experienced this on a build pipeline in Azure Devops. I was using a local agent to run the pipeline on (my own machine). It appears that there was code in the working directory that was causing this conflict, and by default, the agent doesn’t clean the working directory before starting the pipeline process.

The fix was to delete the contents of the working directory on the agent. I did this by selecting the option to clean the working directory:

Clean the working directory in Azure Devops get sources page

I had this when my folder structure got messed up. I’m using Visual Studio 2019 and switched branches that has different folder structure. Some folders got added up in the file explorer and didn’t get deleted even if I switched branches. All I did was to delete those folders that weren’t part of my current branch and it worked.

This error can also happen if you accidentally copied an project file into another projects folder.

I had this kind of Errors in my Blazor Server project when I tried to add .NET Standard Class Library project in Visual Studio 2019.

Errors:

Errors

To fix this i tried following ways.

.csproj file Before

Before

.csproj file After

Solution

I commented out the offending attribute

// obj/Debug/netcoreapp3.1/.NETCoreApp,Version=v3.1.AssemblyAttributes.cs

using System;
using System.Reflection;
//[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v3.1", FrameworkDisplayName = "")]

I was able to solve this issue by getting a new clone of the project.

Solution 1

I was also getting this error in VS Code and the following fixed it.

I have a project/solution with three projects within in.

  • netstandard2.1
  • netstandard2.1
  • netcoreapp3.1

I added the following line to each of the *.csproj files within the <PropertyGroup> section:

<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>

Full example

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

  <PropertyGroup>
    <TargetFramework>netstandard2.1</TargetFramework>
    <GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
  </PropertyGroup>

</Project>

After doing the above you might need to clean /bin and /obj folders for each project.

This article pointed me in the right direction though nothing online that I found mentioned the attribute above. I just guessed and it worked!

Solution 2

Add the following two lines to the <PropertyGroup>. This fixed it for me.

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

Solution 3

The problem was about my folder structure : the test project was in the main project folder. Passing each side by side in the same repo solved the problem

MyProject
   src/MyProject.csproj
   tests/MyTestProject.csproj

Taken from Github issue : https://github.com/dotnet/core/issues/4837

Solution 4

I fixed this by deleting the obj and bin folders in each project directory. I then cleaned the solution and rebuilt. The rebuild succeeded.

Solution 5

You just need to exclude the obj folder from the project/solution.

Comments

  • When I build my application I get the following error

     Error  CS0579  Duplicate 'global::System.Runtime.Versioning.TargetFrameworkAttribute' attribute    MyUIApp
    D:MyUIAppobjDebugnetcoreapp3.1.NETCoreApp,Version=v3.1.AssemblyAttributes.cs   4   Active
    

    The following code is autogenerated in the obj/Debug/netcoreapp3.1 folder

    //
    using System;
    using System.Reflection;
    [assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(«.NETCoreApp,Version=v3.1», FrameworkDisplayName = «»)]

    I have a project file starting with

    <Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
      <PropertyGroup>
        <TargetFramework>netcoreapp3.1</TargetFramework>
        <OutputType>Library</OutputType>
        <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..</SolutionDir>
        <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
        <RestorePackages>true</RestorePackages>
        <UseWindowsForms>true</UseWindowsForms>
      </PropertyGroup>
      <PropertyGroup>
    

    I can work around the issue by commenting out the contents of the file, but not by deleting the file.

Recents

Related

Понравилась статья? Поделить с друзьями:
  • Ошибка cs0200 невозможно присвоить значение свойству или индексатору
  • Ошибка cs0165 использование локальной переменной которой не присвоено значение
  • Ошибка cs0161 не все пути к коду возвращают значение
  • Ошибка cs0120 для нестатического поля метода или свойства
  • Ошибка cs0106 модификатор public недопустим для этого элемента