我有一个项目,在编译时产生以下错误:

重复'AssemblyVersion'属性

我检查了文件AssemblyInfo.cs,看起来没有重复。

我在MSDN上找到了这篇文章,它解决了一个类似的问题,并按照这篇文章中的建议解决了这个问题。

有人能告诉我这是怎么回事吗?这种情况是否只发生在有两个或多个类名称相似的项目的情况下?还是其他原因?


当前回答

当将core升级到VS2017时,另一个解决方案是在属性\assemblyinfo.cs文件中删除它们。

因为它们现在存储在项目中。

其他回答

我在过去也遇到过这个问题,所以我假定构建过程在提供版本控制时分别提供程序集信息。这将导致重复,因为您的项目在AssemblyInfo.cs文件中也有该信息。所以删除文件,我认为它应该工作。

obj\Debug\netstandard2.0\PacktLibrary.AssemblyInfo.cs(15,12): error CS0579: Duplicate 'System.Reflection.AssemblyConfigurationAttribute' attribute [c:\Users\John_Tosh1\Documents\C#8.0and.NetCore3.0\Code\Chapter05\PacktLibrary\PacktLibrary.csproj]
obj\Debug\netstandard2.0\PacktLibrary.AssemblyInfo.cs(16,12): error CS0579: Duplicate 'System.Reflection.AssemblyFileVersionAttribute' attribute [c:\Users\John_Tosh1\Documents\C#8.0and.NetCore3.0\Code\Chapter05\PacktLibrary\PacktLibrary.csproj]
obj\Debug\netstandard2.0\PacktLibrary.AssemblyInfo.cs(17,12): error CS0579: Duplicate 'System.Reflection.AssemblyInformationalVersionAttribute' attribute [c:\Users\John_Tosh1\Documents\C#8.0and.NetCore3.0\Code\Chapter05\PacktLibrary\PacktLibrary.csproj]
obj\Debug\netstandard2.0\PacktLibrary.AssemblyInfo.cs(18,12): error CS0579: Duplicate 'System.Reflection.AssemblyProductAttribute' attribute [c:\Users\John_Tosh1\Documents\C#8.0and.NetCore3.0\Code\Chapter05\PacktLibrary\PacktLibrary.csproj]
obj\Debug\netstandard2.0\PacktLibrary.AssemblyInfo.cs(19,12): error CS0579: Duplicate 'System.Reflection.AssemblyTitleAttribute' attribute [c:\Users\John_Tosh1\Documents\C#8.0and.NetCore3.0\Code\Chapter05\PacktLibrary\PacktLibrary.csproj]
obj\Debug\netstandard2.0\PacktLibrary.AssemblyInfo.cs(20,12): error CS0579: Duplicate 'System.Reflection.AssemblyVersionAttribute' attribute [c:\Users\John_Tosh1\Documents\C#8.0and.NetCore3.0\Code\Chapter05\PacktLibrary\PacktLibrary.csproj]

我相信我的库文件夹是由于无意中创建了另一个类库而损坏的。我删除了所有相关文件库,但问题仍然存在。我通过删除目录中的所有bin和obj文件夹找到了一个解决方案。之前的构建是正常的,但是发现了一个具有相同的assemblyinfo.cs文件的子文件夹。

我刚刚帮助一个团队成员通过重命名回购文件夹重新克隆回购解决了这个问题。这只是一个开发人员的问题,因为团队中的其他人都能够在构建master时不碰到这个错误,所以我们知道这个问题不是源代码的问题。

我们确实尝试删除bin和obj文件夹,并执行git clean -xfd,但这些都没有解决这个问题。在这种情况下,用一个干净的回购副本重新开始是有效的。

当我改变文件夹结构并尝试推送时,我也遇到了同样的问题。少管所让我先拔,我就拔了。这在旧文件夹和新文件夹中复制了我的源代码,所以在构建时出现了很多复制错误。

只需删除重复的文件夹就可以解决这个问题。

对我来说,AssembyInfo.cs和SolutionInfo.cs有不同的值。所以也检查一下这些文件。我只是把其中一个版本删除了。