Resolving C# Compilation Error CS0579: Duplicate AssemblyVersion Attribute

Nov 23, 2025 · Programming · 10 views · 7.8

Keywords: C# | Compilation Error | AssemblyVersion

Abstract: This article provides an in-depth analysis of the common CS0579 compilation error in C# projects, typically caused by duplicate AssemblyVersion attributes. It explains the conflict mechanism between the new project system's automatic assembly info generation in Visual Studio 2017 and later versions, and the traditional AssemblyInfo.cs file. By comparing multiple solutions, the article highlights the best practice of removing the AssemblyInfo.cs file, with complete code examples and configuration instructions to fundamentally resolve version attribute duplication issues.

Problem Background and Analysis

During C# project development, developers frequently encounter the CS0579 compilation error, which explicitly indicates the presence of duplicate "AssemblyVersion" attributes. The root cause of this issue lies in the conflict between modern .NET project build systems and traditional assembly information management approaches.

Error Generation Mechanism

Starting from Visual Studio 2017, the new .NET SDK project system introduced automatic assembly information generation. When the project file contains the <Project Sdk="Microsoft.NET.Sdk"> declaration, the build system automatically generates assembly attributes for the project, including AssemblyVersion, AssemblyFileVersion, and others. If the project simultaneously contains a traditional AssemblyInfo.cs file that defines the same assembly attributes, it results in attribute duplication, triggering the CS0579 compilation error.

Core Solution

According to best practices, the most direct solution is to remove the AssemblyInfo.cs file from the project. This file was used in traditional .NET Framework projects to centrally manage assembly metadata but has become redundant in the new project system. After removing this file, the project will rely entirely on automatically generated assembly information, thereby eliminating the possibility of attribute duplication.

Alternative Solution Analysis

For cross-platform projects that need to support both .NET Framework and .NET Standard, consider disabling the automatic assembly information generation feature. Add the following configuration to the project file:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
  </PropertyGroup>
</Project>

This approach allows continued use of the AssemblyInfo.cs file but requires developers to manually manage all assembly attributes, making it suitable for scenarios with specific version control requirements.

Practical Recommendations

When migrating old projects to the new project system, prioritize removing the AssemblyInfo.cs file. If the project contains custom assembly attributes, migrate them to the project file using the <AssemblyAttribute> element or generate them dynamically via build scripts. For newly created projects, directly using the SDK's automatic generation feature is the optimal choice, simplifying project configuration and reducing maintenance costs.

In-Depth Understanding

The essence of this issue reflects the evolution of the .NET ecosystem from traditional MSBuild projects to modern SDK-style projects. The new project system, through the principle of convention over configuration, reduces redundant configuration files and improves development efficiency. Understanding this architectural change helps developers better adapt to modern .NET development patterns and avoid similar compatibility issues.

Copyright Notice: All rights in this article are reserved by the operators of DevGex. Reasonable sharing and citation are welcome; any reproduction, excerpting, or re-publication without prior permission is prohibited.