Error CS0579 Duplicate 'global::System.Runtime.Versioning.TargetFrameworkAttribute'

被刻印的时光 ゝ 提交于 2020-07-09 12:47:08

问题


When I build my application I get the following error

 Error  CS0579  Duplicate 'global::System.Runtime.Versioning.TargetFrameworkAttribute' attribute    MyUIApp
D:\MyUIApp\obj\Debug\netcoreapp3.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.


回答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.




回答2:


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.




回答3:


I solved the problem the way explained in the Github issue : https://github.com/dotnet/core/issues/4837

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




回答4:


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:

<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>

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



来源:https://stackoverflow.com/questions/61997928/errorcs0579duplicate-globalsystem-runtime-versioning-targetframeworkattribu

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!