当我构建我的应用程序时,我收到以下错误
Error CS0579 Duplicate 'global::System.Runtime.Versioning.TargetFrameworkAttribute' attribute MyUIApp
D:\MyUIApp\obj\Debug\netcoreapp3.1\.NETCoreApp,Version=v3.1.AssemblyAttributes.cs 4 Active
Run Code Online (Sandbox Code Playgroud)
obj/Debug/netcoreapp3.1文件夹下自动生成以下代码
// 使用系统;使用 System.Reflection; [程序集: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v3.1", FrameworkDisplayName = "")]
我有一个以开头的项目文件
<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>
Run Code Online (Sandbox Code Playgroud)
我可以通过注释掉文件的内容来解决这个问题,但不能通过删除文件来解决。
wsa*_*oht 58
我也在 VS Code 中遇到了这个错误,以下修复了它。
我有一个项目/解决方案,其中包含三个项目。
我向该部分中的每个*.csproj文件添加了以下行<PropertyGroup>:
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
Run Code Online (Sandbox Code Playgroud)
完整示例
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
后做上述可能需要清洁/bin和/obj文件夹的每个项目。
这篇文章为我指明了正确的方向,尽管我在网上发现的任何内容都没有提到上面的属性。我只是猜测,它奏效了!
小智 42
将以下两行添加到<PropertyGroup>. 这为我修好了。
<PropertyGroup>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
小智 32
所以我确实在基于 .NET 4.7 的解决方案上遇到了同样的情况,花了几个小时,才发现我的一位同事确实在项目中包含了 obj 和 bin 文件夹!排除它们解决了问题并且该错误消失了。
希望这能为某人节省几个小时。
Cla*_*doo 14
问题出在我的文件夹结构上:测试项目位于主项目文件夹中。在同一个 repo 中并排传递解决了这个问题
MyProject
src/MyProject.csproj
tests/MyTestProject.csproj
Run Code Online (Sandbox Code Playgroud)
取自 Github 问题:https : //github.com/dotnet/core/issues/4837
Joe*_*ely 12
您只需obj从项目/解决方案中排除该文件夹即可。如果您不知道如何执行此操作,请将其添加到您的 .csproj 或 .vbproj 或 .whateverproj 中:
<ItemGroup>
<Compile Remove="obj\**" />
<Content Remove="obj\**" />
<EmbeddedResource Remove="obj\**" />
<None Remove="obj\**" />
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
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.
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.
.sln file.sln使用任何代码编辑器打开您的文件.sln文件在根目录中这就是您的项目文件引用现在的样子。
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApplication2", "WebApplication2\WebApplication2.csproj", "{027937D8-D0E6-45A4-8846-C2E28DA102E6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApplication2.Tests", "WebApplication2.Tests\WebApplication2.Tests.csproj", "{AD4C6C31-F617-4E76-985A-32B0E3104004}"
EndProject
Run Code Online (Sandbox Code Playgroud)
就是这样。只需重新加载您的解决方案并快乐编码!
| 归档时间: |
|
| 查看次数: |
34715 次 |
| 最近记录: |