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

重复'AssemblyVersion'属性

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

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

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


当前回答

编辑AssemblyInfo.cs和#if !NETCOREAPP3_0…# endif

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.

#if !NETCOREAPP3_0  

[assembly: AssemblyTitle(".Net Core Testing")]
[assembly: AssemblyDescription(".Net Core")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct(".Net Core")]
[assembly: AssemblyCopyright("Copyright ©")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components.  If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("000b119c-2445-4977-8604-d7a736003d34")]

// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

#endif

其他回答

我的错误发生是因为,不知何故,在我的控制器文件夹中创建了一个obj文件夹。只需在应用程序中搜索Assemblyinfo.cs中的一行。某处可能有副本。

在将旧项目转换为. net Core时,现在可以在项目本身设置AssemblyInfo.cs中的大部分信息。打开项目属性并选择Package选项卡以查看新的设置。

埃里克·l·安德森的帖子 “复制”System.Reflection。AssemblyCompanyAttribute ' attribute"描述了3个选项:

从AssemblyInfo.cs文件中删除冲突项, 完全删除文件或 禁用GenerateAssemblyInfo(在Serge Semenov的另一个回答中建议)

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

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

在我的例子中,在编译期间生成的一些临时*.cs文件被意外添加到项目中。

这些文件来自obj\Debug目录,所以它们肯定不应该被添加到解决方案中。A *.cs通配符有点疯狂,错误地添加了它们。

删除这些文件解决了这个问题。

在我的例子中,在项目中有一个子文件夹,它本身就是一个项目文件夹:

文件系统: c: \ \ webapi \ wepapi.csproj项目 c: \ \ webapi \ \ wepapitests.csproj测试项目 解决方案 Webapi(文件夹和项目) 测试(文件夹) 测试(文件夹和项目)

然后我不得不从“webapi”项目中删除子文件夹“tests”。

EDIT 2022:为了更清楚,正如@bobt在评论中提到的那样,我说的“删除”是指:右键单击webapi中的“测试”文件夹,并选择“排除项目”选项。