Duplicate AssemblyVersion Attribute

2019-01-22 16:59发布

问题:

I have a project that generates following error on compilation:

error CS0579: Duplicate 'AssemblyVersion' attribute

I have checked the file AssemblyInfo.cs and it looks like there is no duplication there.

I found this article on MSDN which addresses a similar problem and following the suggestion in this article fixes the problem as well.

Can anyone tell me what's going on here? Does it happen only in case of having two or more projects with classes having similar names? Or is it something else?

回答1:

Since I have also run into this issue in the past, so I am going to assume that your build process also provides assembly information seperately to provide versioning. And that cause a duplication as your project also has that info in the AssembleyInfo.cs file. So remove the file and I think it should work.



回答2:

Starting from Visual Studio 2017 another solution to keep using the AssemblyInfo.cs file is to turn off automatic assembly info generation like this:

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

I personally find it very useful for projects which need to support both .NET Framework and .NET Standard.



回答3:

I had the same error and was underling the Assembly Vesrion and Assembly File Version so reading Luqi answer I just added them as comments and the error was solved

// AssemblyVersion is the CLR version. Change this only when making breaking    changes
//[assembly: AssemblyVersion("3.1.*")]
// AssemblyFileVersion should ideally be changed with each build, and should help identify the origin of a build
//[assembly: AssemblyFileVersion("3.1.0.0")]


回答4:

In my case, some temporary *.cs files generated during compilation got accidentally added to the project.

The files were from the obj\Debug directory, so they definitely shouldn't have been added to the solution. A *.cs wildcard went a little crazy and added them incorrectly.

Deleting these files fixed the problem.



回答5:

When converting an older project to .NET Core, most of the information that was in the AssemblyInfo.cs can now be set on the project itself. Open the project properties and select the Package tab to see the new settings.

The Eric L. Anderson's post "Duplicate ‘System.Reflection.AssemblyCompanyAttribute’ attribute" describes 3 options :

  • remove the conflicting items from the AssemblyInfo.cs file,
  • completely delete the file or
  • disable GenerateAssemblyInfo (as suggested in another answer by Serge Semenov)


回答6:

For me it was that AssembyInfo.cs and SolutionInfo.cs had different values. So check these files as well. I just removed the version from one of them.



回答7:

In my case, there where a subfolder in a project that was a project folder it self:

  • file system:

    • c:\projects\webapi\wepapi.csproj
    • c:\projects\webapi\tests\wepapitests.csproj
  • solution

    • webapi (folder and project)
      • tests (folder)
    • tests (folder and project)

Then i had to remove the subfolder "tests" from the "webapi" project.



回答8:

My error occurred because, somehow, there was an obj folder created inside my controllers folder. Just do a search in your application for a line inside your Assemblyinfo.cs. There may be a duplicate somewhere.



回答9:

This usually happens for me if I compiled the project in Visual Studio 2017 & then I try to rebuild & run it with .NET Core with the command line command "dotnet run".

Simply deleting all the "bin" & "obj" folders - both inside "ClientApp" & directly in the project folder - allowed the .NET Core command "dotnet run" to rebuild & run successfully.



回答10:

My error was that I was also referencing another file in my project, which was also containing a value for the attribute "AssemblyVersion". I removed that attribute from one of the file and it is now working properly.

The key is to make sure that this value is not declared more than once in any file in your project.



回答11:

Yet another solution when upgrading core to VS2017 is to remove them in the properties\assemblyinfo.cs file.

Since they now are stored in the project.