C# – Duplicate ‘AssemblyVersion’ attribute


You’re trying to add the AssemblyVersion attribute to your project, like this:

using System.Reflection; [assembly: AssemblyVersion("")] [assembly: AssemblyFileVersion("")]
Code language: C# (cs)

And you get the following compiler errors:

Error CS0579 Duplicate ‘AssemblyVersion’ attribute

Error CS0579 Duplicate ‘AssemblyFileVersion’ attribute

But you don’t see these attributes anywhere else in your project.


The problem is Visual Studio auto-generates the assembly info by default.

To turn this off, put the following in your .csproj file:

<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netcoreapp3.1</TargetFramework> </PropertyGroup> <PropertyGroup> <GenerateAssemblyInfo>false</GenerateAssemblyInfo> </PropertyGroup> </Project>
Code language: HTML, XML (xml)

Where is the auto-generated assembly info?

My assembly is called DupeAssemblyVersion and I’m targeting .NET Core 3.1. So the auto-generated assembly info file is here: \obj\Debug\netcoreapp3.1\DupeAssemblyVersion.AssemblyInfo.cs.

Here’s what this file looks like:

//------------------------------------------------------------------------------ // <auto-generated> // This code was generated by a tool. // Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // </auto-generated> //------------------------------------------------------------------------------ using System; using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("DupeAssemblyVersion")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")] [assembly: System.Reflection.AssemblyProductAttribute("DupeAssemblyVersion")] [assembly: System.Reflection.AssemblyTitleAttribute("DupeAssemblyVersion")] [assembly: System.Reflection.AssemblyVersionAttribute("")] // Generated by the MSBuild WriteCodeFragment class.
Code language: C# (cs)

Leave a Comment