Duplicate 'AssemblyVersion' attribute in C#
By Tan Lee Published on Mar 20, 2025 121
When you try to add the AssemblyVersion attribute to your project, for example, to auto-increment the version:
using System.Reflection; [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]
You may encounter 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.
Solution
The issue arises because Visual Studio automatically generates the assembly information by default.
To disable this auto-generation, add the following to your .csproj
file:
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netcoreapp3.1</TargetFramework> </PropertyGroup> <PropertyGroup> <GenerateAssemblyInfo>false</GenerateAssemblyInfo> </PropertyGroup> </Project>
Where is the auto-generated assembly info located?
If your assembly is called DupeAssemblyVersion
and you're targeting .NET Core 3.1, the auto-generated assembly info will be found at:
\obj\Debug\netcoreapp3.1\DupeAssemblyVersion.AssemblyInfo.cs
Here’s an example of 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("1.0.0.0")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")] [assembly: System.Reflection.AssemblyProductAttribute("DupeAssemblyVersion")] [assembly: System.Reflection.AssemblyTitleAttribute("DupeAssemblyVersion")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] // Generated by the MSBuild WriteCodeFragment class.
By turning off the auto-generation of assembly info, you can prevent the Duplicate ‘AssemblyVersion’ attribute
error from occurring.
Categories
Popular Posts
11 Things You Didn't Know About Cloudflare
Dec 19, 2024
Portal HTML Bootstrap
Nov 13, 2024
Plus Admin Dashboard Template
Nov 18, 2024
Modular Admin Template
Nov 14, 2024