我有一个项目,在编译时产生以下错误:
重复'AssemblyVersion'属性
我检查了文件AssemblyInfo.cs,看起来没有重复。
我在MSDN上找到了这篇文章,它解决了一个类似的问题,并按照这篇文章中的建议解决了这个问题。
有人能告诉我这是怎么回事吗?这种情况是否只发生在有两个或多个类名称相似的项目的情况下?还是其他原因?
我有一个项目,在编译时产生以下错误:
重复'AssemblyVersion'属性
我检查了文件AssemblyInfo.cs,看起来没有重复。
我在MSDN上找到了这篇文章,它解决了一个类似的问题,并按照这篇文章中的建议解决了这个问题。
有人能告诉我这是怎么回事吗?这种情况是否只发生在有两个或多个类名称相似的项目的情况下?还是其他原因?
当前回答
在我的例子中,在编译期间生成的一些临时*.cs文件被意外添加到项目中。
这些文件来自obj\Debug目录,所以它们肯定不应该被添加到解决方案中。A *.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文件的子文件夹。
我在。net框架上的项目中也有同样的错误,通过删除项目文件夹中的packages/GitVersion*解决了这个问题
我在msdn上找到了这个答案,这解释了将文件标记为内容,然后复制到输出= If更新。请看下面的文章:
https://social.msdn.microsoft.com/Forums/en-US/8671bdff-9b16-4b49-ba9e-227cc4df31b2/compile-error-cs0579-duplicate-assemblyversion-attribute?forum=vsgatk
GH
我刚从。net Framework切换到。net Core就出现了错误。我的Visual Studio解决方案中有2个类库项目。我发现其中一个项目有一个名为AssemblyInfo.cs的文件,而另一个项目没有这个文件。该文件位于Properties文件夹下。我只是删除了属性文件夹,一切工作正常。
这个问题是VS 2017特有的参考冲突。
我通过在AssemblyInfo.cs中注释掉第7 -14行以及页面底部的程序集版本代码来解决了同样的错误
它删除了所有重复的引用,项目能够重新构建。