9

I have 2 projects in a solution, and I am not sure why I am running into this error for the 1st project when building the solution.

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

I've tried the following answer, Cleaned and Rebuilt, but it didn't help.

Add the following two lines to the <PropertyGroup>.

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

And this answer says to delete the assemeblyinfo.cs file from project under properties menu and rebuild it, but I don't even see an Assemblyinfo.cs file under properties...

properties

I've also commented out the assembly line per a different answer, and still it failed:

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

Here are my .csproj files:

Project1:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
      <TargetFramework>netcoreapp3.1</TargetFramework>
      <AzureFunctionsVersion>v3</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="3.0.10" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.3" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\DI\DI.csproj" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="HttpTrigger1/readme.md">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>
</Project>

Project2:

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Azure.Storage.Files.DataLake" Version="12.6.0" />
    <PackageReference Include="Azure.Storage.Queues" Version="12.6.0" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\DI\DI.csproj" />
  </ItemGroup>

</Project>
halfer
  • 19,824
  • 17
  • 99
  • 186
Cataster
  • 3,081
  • 5
  • 32
  • 79

4 Answers4

9

I got this error because I integrated two projects by removing the csproj file from Project A then including the root folder in Project B. I failed to remove the .bin and .obj folders from Project A. Hope this saves somebody some unnecessary grief.

Bill Matsoukas
  • 153
  • 1
  • 5
6

Deleting Assembly files from Release and Debug folder resolved the issue. They must've been added at some point when I built the project.

Cataster
  • 3,081
  • 5
  • 32
  • 79
6

Solved by running git clean -xdf to remove artefacts from previous builds. After that, built successfully.

Andrew Hong
  • 69
  • 1
  • 2
1

I got the same problem after suppressing a level of hierarchy in my solution. The folder structure was like

/Project
  /WebApi
    /WebApi
      /WebApi
        Program.cs
        webapi.csproj

I wanted to suppress a level of hierarchy so I copied the last WebApi under the first WebApi folder. After copying the projects I forgot to delete the source folders and began to experience the same error as you.

It was due to duplicated project folders :

/Project
  /WebApi
    /WebApi
      Program.cs
      webapi.csproj
      /WebApi
        Program.cs   
        webapi.csproj

After original folder deletion the problem was gone, final hierachy:

/Project
  /WebApi
    /WebApi
      Program.cs
      webapi.csproj
bN_
  • 772
  • 14
  • 20