Kirsten
Kirsten

Reputation: 18188

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

I am trying to build several c# netstandard2.0 dlls and one netcoreapp3.1 application in DevOps

AssemblyInfo.cs for the .exe contains the following AssemblyInfo

I can build on my pc.

However the build in DevOps fails with the error

 (CoreCompile target) -> 
         obj\Release\netcoreapp3.1\.NETCoreApp,Version=v3.1.AssemblyAttributes.cs(4,12): error CS0579: Duplicate 'global::System.Runtime.Versioning.TargetFrameworkAttribute' attribute

THe task in DevOps is

- task: DotNetCoreCLI@2
  inputs:
    command: pack
    packagesToPack: '**/SBD.*.csproj'
    versioningScheme: byPrereleaseNumber
    majorVersion: '$(Major)'
    minorVersion: '$(Minor)'
    patchVersion: '$(Patch)'

Upvotes: 2

Views: 12609

Answers (2)

John Erbynn
John Erbynn

Reputation: 375

This worked for me;

I commented(removed) <TargetFramework> property in one of the .cproj's files.

Upvotes: 0

LoLance
LoLance

Reputation: 28196

The error comes from the auto-generated file .NETCoreApp,Version=v3.1.AssemblyAttributes.cs, I think it has something to with your custom AssemblyInfo.cs file.

For .net core(new SDK fprmat) project, it doesn't contain the AssemblyInfo.cs file by default like .net framework (old legacy format). Instead we can set those values in its project file, and it will generate the xx.AssemblyAttributes.cs and ProjectName.AssemblyInfo.cs for us. I assume there's conflict between your custom AssemblyInfo.cs and the auto-generated files.

So you need to set <GenerateAssemblyInfo>false</GenerateAssemblyInfo> to use your custom AssemblyInfo.cs file. Check the similar ticket in Github/Dotnet-SDK.

Upvotes: 3

Related Questions