8000 error CS0579: Duplicate 'global::System.Runtime.Versioning.TargetFrameworkAttribute' attribute · Issue #12297 · dotnet/sdk · GitHub
[go: up one dir, main page]

Skip to content

error CS0579: Duplicate 'global::System.Runtime.Versioning.TargetFrameworkAttribute' attribute #12297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
rogebrd opened this issue Jun 30, 2020 · 10 comments
Assignees

Comments

@rogebrd
Copy link
rogebrd commented Jun 30, 2020

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:

net45obj\Debug\.NETFramework,Version=v4.5.AssemblyAttributes.cs(4,12): error CS0579: Duplicate 'global::System.Runtime. Versioning.TargetFrameworkAttribute' attribute [dropbox-sdk-dotnet\dropbox-sdk-dotnet\Dropbox.Api\ Dropbox.Api.NetStandard.csproj] net45obj\Release\.NETFramework,Version=v4.5.AssemblyAttributes.cs(4,12): error CS0579: Duplicate 'global::System.Runtim e.Versioning.TargetFrameworkAttribute' attribute [dropbox-sdk-dotnet\dropbox-sdk-dotnet\Dropbox.Ap i\Dropbox.Api.NetStandard.csproj] portable40obj\Debug\.NETPortable,Version=v4.0,Profile=Profile344.AssemblyAttributes.cs(4,12): error CS0579: Duplicate ' global::System.Runtime.Versioning.TargetFrameworkAttribute' attribute [dropbox-sdk-dotnet\dropbox- sdk-dotnet\Dropbox.Api\Dropbox.Api.NetStandard.csproj] portable40obj\Release\.NETPortable,Version=v4.0,Profile=Profile344.AssemblyAttributes.cs(4,12): error CS0579: Duplicate 'global::System.Runtime.Versioning.TargetFrameworkAttribute' attribute [dropbox-sdk-dotnet\dropbo x-sdk-dotnet\Dropbox.Api\Dropbox.Api.NetStandard.csproj] portableobj\Debug\.NETPortable,Version=v4.5,Profile=Profile111.AssemblyAttributes.cs(4,12): error CS0579: Duplicate 'gl obal::System.Runtime.Versioning.TargetFrameworkAttribute' attribute [dropbox-sdk-dotnet\dropbox-sd k-dotnet\Dropbox.Api\Dropbox.Api.NetStandard.csproj] portableobj\Release\.NETPortable,Version=v4.5,Profile=Profile111.AssemblyAttributes.cs(4,12): error CS0579: Duplicate ' global::System.Runtime.Versioning.TargetFrameworkAttribute' attribute [dropbox-sdk-dotnet\dropbox- sdk-dotnet\Dropbox.Api\Dropbox.Api.NetStandard.csproj] obj\Release\netstandard2.0\.NETStandard,Version=v2.0.AssemblyAttributes.cs(4,12): error CS0579: Duplicate 'global::Syst em.Runtime.Versioning.TargetFrameworkAttribute' attribute [dropbox-sdk-dotnet\dropbox-sdk-dotnet\D ropbox.Api\Dropbox.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

@marcpopMSFT marcpopMSFT added the untriaged Request triage from a team member label Jul 10, 2020
@pikadun
Copy link
pikadun commented Jul 18, 2020

I also encountered the same problem.

I created a console project with dotnet cli.
After run command dotnet build, I got an error that Duplicate 'global::System.Runtime.Versio 8000 ning.TargetFrameworkAttribute' attribute in ~/obj/Debug/net5.0/.NETCoreApp,Version=v5.0.AssemblyAttributes.cs:

// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v5.0", FrameworkDisplayName = "")]

It duplicate with project file .csproj

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>

</Project>

OS Version: Windows 10 Linux Subsystem, BUILD: 19041, RELEASE: Ubuntu 20.04 LTS
DOTNET Version: 5.0.100-preview.6.20318.15

@joeloff joeloff removed the untriaged Request triage from a team member label Aug 5, 2020
@joeloff
Copy link
Member
joeloff commented Aug 5, 2020

@rogebrd Can you generate a binlog, then search for AssemblyInfo.cs. It's possible the SDK globbing is pulling in an assembly.info file that exsits somewhere in the sources or cache under the obj folder.

@CreepyGnome
Copy link

This exact issue just started occurring for me this morning, just on my box. Our CICD is fine and asked around and no one else is having this issue on their local boxes. I tried a full clean and still occurs. If I add the below to the problem csproj files it goes away. However I should not need to have this, and I cannot check them in as no one else I can find has this issue. It seem related to .NET 5.

I am using .NET 5.0.102 and I tried it in an IDE and via dotnet CLI and get the same issue. With no changes to our CSproj files in like 2 months not sure how everything was fine on Friday and then Monday morning this is now happening.

The below additions to a CSProj files makes the errors go away and allows me to make progress on other things, but is a horrible experience as I have to ensure I don't check them in and I have to undo the changes many time and restore them either manually or via a stash depending on the situation.

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

I have done a full clean and it didn't address the issue. I even manually deleted all the bin and obj folders and still occurs on a build.

FINAL SOLUTION

What I had to do to finally get this error to go away without changing the CSproj files was to delete the directory and re-clone the repository and then it went away.

So .NET went screwy it seems and did something similar to what @joeloff mentioned above that requires basically delete and re-clone for some reason to resolve.

Viir added a commit to pine-vm/pine that referenced this issue Aug 10, 2021
…ibute'

`dotnet test` in `implement/test-elm-fullstack` sometimes failed with errors like these:

```
elm-fullstack\implement\test-elm-fullstack\obj\Debug\netcoreapp3.1\.NETCoreApp,Version=v3.1.AssemblyAttributes.cs(4,12): error CS0579: Duplicate 'global::System.Runtime.Versioning.TargetFrameworkAttribute' attribute [elm-fullstack\implement\test-elm-fullstack\test-elm-fullstack.csproj]
elm-fullstack\implement\test-elm-fullstack\obj\Debug\netcoreapp3.1\test-elm-fullstack.AssemblyInfo.cs(14,12): error CS0579: Duplicate 'System.Reflection.AssemblyCompanyAttribute' attribute [elm-fullstack\implement\test-elm-fullstack\test-elm-fullstack.csproj]
[...]
```

An alternative way to work around these errors is to remove garbage files in the repository automatically created by .net tooling.

For discussion of this issue, see also dotnet/sdk#12297 and dotnet/sdk#14286
@rohitarora303
Copy link

For me this started appearing after updating the VS2019 to 16.11.3 directly from 16.10.xx after a year, and was able to resolve by adding <GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute> in failing projects from solution. I am still using 4.6.1 though

@AraHaan
Copy link
Member
AraHaan commented Nov 19, 2021

Now that Source Generators exist why cant we just have it generated in part from an source generator in the .NET SDK but with them able to disable it when they want to?

I feel like this can eliminate the possible duplication entirely as well as helping to obtain reproducible builds and also fix another issue where FrameworkDisplayName is empty within that attribute as well at the same time.

@rohitarora303
Copy link

It started with me when I updated my Visual Studio which brought .net sdk 5.0 alongwith it and then adding

<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute> to the failing projects worked for me

@BDisp
Copy link
BDisp commented Jan 17, 2023

I also had to remove the repo and re-clone. Probably any bin/obj folder that needed to be deleted, but on this huge repo is very exhausting doing that by hand.

@tossnet
Copy link
tossnet commented Sep 23, 2023

I've had these problems when I create projects in the same folder as the solution. By putting my projects in sub-folders and then manually modifying the .sln file, no more these errors ✅

@seangwright
Copy link

I had this problem start randomly with a .NET 8 app. The solution contains multiple projects all which built except for 1 - an ASP.NET Core app.

I tried running dotnet clean and dotnet-purge but neither fixed the build errors.

I was able to resolve the issue by re-cloning the project into a new folder (and then copying all my git-ignored local settings files over). However, after about 1 hour of work the problem appeared again and I couldn't build the solution.

I was about to accept that this re-clone workflow would now be part of my development cycle (because I still don't know the cause), but I asked Copilot to create a PowerShell script that would remove any build artifacts that could cause this kind of error. Here's what it generated.

#!/usr/bin/env pwsh

$foldersToRemove = @(
    "bin",
    "obj",
    "TestResults", # Common test output directory
    "node_modules", # NPM packages
    ".vs", # Visual Studio temporary files
    "BenchmarkDotNet.Artifacts" # Benchmark results
)

$solutionRoot = $PSScriptRoot

Write-Host "Cleaning build artifacts in: $solutionRoot"

foreach ($folder in $foldersToRemove) {
    Write-Host "Searching for $folder directories..."
    $items = Get-ChildItem -Path $solutionRoot -Filter $folder -Directory -Recurse
    
    foreach ($item in $items) {
        Write-Host "Removing $($item.FullName)"
        try {
            Remove-Item -Path $item.FullName -Recurse -Force
            Write-Host "Successfully removed $($item.FullName)" -ForegroundColor Green
        }
        catch {
            Write-Host "Failed to remove $($item.FullName): $($_.Exception.Message)" -ForegroundColor Red
        }
    }
}

Write-Host "`nBuild artifact cleanup complete!" -ForegroundColor Green

I ran this in the same directory as my .sln file. Then I ran dotnet build and it worked! The only thing that seems relevant to my project is the additional cleaning of the node_modules folder, but I don't understand how that could have an impact.

@pferreirafabricio
Copy link

I had this problem start randomly with a .NET 8 app. The solution contains multiple projects all which built except for 1 - an ASP.NET Core app.

I tried running dotnet clean and dotnet-purge but neither fixed the build errors.

I was able to resolve the issue by re-cloning the project into a new folder (and then copying all my git-ignored local settings files over). However, after about 1 hour of work the problem appeared again and I couldn't build the solution.

I was about to accept that this re-clone workflow would now be part of my development cycle (because I still don't know the cause), but I asked Copilot to create a PowerShell script that would remove any build artifacts that could cause this kind of error. Here's what it generated.

#!/usr/bin/env pwsh

$foldersToRemove = @(
"bin",
"obj",
"TestResults", # Common test output directory
"node_modules", # NPM packages
".vs", # Visual Studio temporary files
"BenchmarkDotNet.Artifacts" # Benchmark results
)

$solutionRoot = $PSScriptRoot

Write-Host "Cleaning build artifacts in: $solutionRoot"

foreach ($folder in $foldersToRemove) {
Write-Host "Searching for $folder directories..."
$items = Get-ChildItem -Path $solutionRoot -Filter $folder -Directory -Recurse

foreach ($item in $items) {
    Write-Host "Removing $($item.FullName)"
    try {
        Remove-Item -Path $item.FullName -Recurse -Force
        Write-Host "Successfully removed $($item.FullName)" -ForegroundColor Green
    }
    catch {
        Write-Host "Failed to remove $($item.FullName): $($_.Exception.Message)" -ForegroundColor Red
    }
}

}

Write-Host "nBuild artifact cleanup complete!" -ForegroundColor Green I ran this in the same directory as my .slnfile. Then I randotnet buildand it worked! The only thing that seems relevant to my project is the additional cleaning of thenode_modules` folder, but I don't understand how that could have an impact.

@seangwright Thanks for the script, it was very helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0