C# 重复的 AssemblyVersion 属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10311347/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Duplicate AssemblyVersion Attribute
提问by Aamir
I have a project that generates following error on compilation:
我有一个在编译时生成以下错误的项目:
error CS0579: Duplicate 'AssemblyVersion' attribute
错误 CS0579:重复的“AssemblyVersion”属性
I have checked the file AssemblyInfo.csand it looks like there is no duplication there.
我检查了文件AssemblyInfo.cs,看起来那里没有重复。
I found this article on MSDNwhich addresses a similar problem and following the suggestion in this article fixes the problem as well.
我在 MSDN 上找到了这篇文章,它解决了一个类似的问题,并且按照本文中的建议也解决了这个问题。
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?
谁能告诉我这里发生了什么?它是否仅在两个或多个项目具有相似名称的类的情况下发生?或者是别的什么?
采纳答案by luqi
I have also run into this issue in the past, so I am going to assume that your build process provides assembly information separately to providing versioning. And that causes a duplication as your project also has that info in the AssemblyInfo.csfile. So remove the file and I think it should work.
我过去也遇到过这个问题,因此我将假设您的构建过程单独提供程序集信息以提供版本控制。这会导致重复,因为您的项目在AssemblyInfo.cs文件中也有该信息。所以删除文件,我认为它应该可以工作。
回答by Mariusz.W
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.
对我来说,是 AssembyInfo.cs 和 SolutionInfo.cs 有不同的值。所以也要检查这些文件。我刚刚从其中一个中删除了版本。
回答by Pantelitsa Mavrovounioti
I had the same error and it was underlining the Assembly Vesrion and Assembly File Version so reading Luqi answer I just added them as comments and the error was solved
我有同样的错误,它在Assembly Vesrion和Assembly File Version下划线,所以阅读Luqi的回答我只是将它们添加为评论,错误就解决了
// 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")]
回答by Nate Barbettini
In my case, some temporary *.cs files generated during compilation got accidentally added to the project.
就我而言,编译期间生成的一些临时 *.cs 文件被意外添加到项目中。
The files were from the obj\Debugdirectory, so they definitely shouldn't have been added to the solution. A *.cswildcard went a little crazy and added them incorrectly.
这些文件来自obj\Debug目录,因此绝对不应该将它们添加到解决方案中。一个*.cs通配符去有点疯狂,并加入他们不正确。
Deleting these files fixed the problem.
删除这些文件解决了这个问题。
回答by Antoine Dijoux
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.
我的错误是我还引用了项目中的另一个文件,该文件也包含属性“AssemblyVersion”的值。我从其中一个文件中删除了该属性,现在它可以正常工作了。
The key is to make sure that this value is not declared more than once in any file in your project.
关键是要确保在项目的任何文件中不会多次声明此值。
回答by Dwayne Love
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.
我的错误发生是因为不知何故,在我的控制器文件夹中创建了一个 obj 文件夹。只需在您的应用程序中搜索您的 Assemblyinfo.cs 中的一行。某处可能有重复。
回答by Serge Semenov
Starting from Visual Studio 2017another solution to keep using the AssemblyInfo.csfile is to turn off automatic assembly info generation like this:
从Visual Studio 2017开始,另一种继续使用该AssemblyInfo.cs文件的解决方案是关闭自动程序集信息生成,如下所示:
<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.
我个人认为它对于需要同时支持 .NET Framework 和 .NET Standard 的项目非常有用。
回答by Michael Freidgeim
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.
将旧项目转换为 .NET Core 时,现在可以在项目本身上设置“AssemblyInfo.cs”中的大部分信息。打开项目属性并选择“包”选项卡以查看新设置。
The Eric L. Anderson's post "Duplicate ‘System.Reflection.AssemblyCompanyAttribute' attribute"describes 3 options :
在埃里克L. Anderson的文章“复制‘System.Reflection.AssemblyCompanyAttribute’属性”描述了3个选项:
- remove the conflicting items from the AssemblyInfo.cs file,
- completely delete the file or
- disable GenerateAssemblyInfo (as suggested in another answer by Serge Semenov)
- 从 AssemblyInfo.cs 文件中删除冲突项,
- 完全删除文件或
- 禁用 GenerateAssemblyInfo(如Serge Semenov 的另一个答案中所建议的)
回答by Thomas Koelle
Yet another solution when upgrading core to VS2017 is to remove them in the properties\assemblyinfo.cs file.
将核心升级到 VS2017 时的另一个解决方案是在 properties\assemblyinfo.cs 文件中删除它们。
Since they now are stored in the project.
因为它们现在存储在项目中。
回答by heringer
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)
- webapi (folder and project)
文件系统:
- c:\projects\webapi\wepapi.csproj
- c:\projects\webapi\tests\wepapitests.csproj
解决方案
- webapi(文件夹和项目)
- 测试(文件夹)
- 测试(文件夹和项目)
- webapi(文件夹和项目)
Then i had to remove the subfolder "tests" from the "webapi" project.
然后我不得不从“webapi”项目中删除子文件夹“tests”。

