-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Comments
I also encountered the same problem. I created a console project with dotnet cli. // <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v5.0", FrameworkDisplayName = "")] It duplicate with project file <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 |
@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. |
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.
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 SOLUTIONWhat 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. |
…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
For me this started appearing after updating the VS2019 to |
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. |
It started with me when I updated my Visual Studio which brought .net sdk 5.0 alongwith it and then adding
|
I also had to remove the repo and re-clone. Probably any |
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 ✅ |
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 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 |
@seangwright Thanks for the script, it was very helpful |
Uh oh!
There was an error while loading. Please reload this page.
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
The text was updated successfully, but these errors were encountered: