我有一个项目,在编译时产生以下错误:
重复'AssemblyVersion'属性
我检查了文件AssemblyInfo.cs,看起来没有重复。
我在MSDN上找到了这篇文章,它解决了一个类似的问题,并按照这篇文章中的建议解决了这个问题。
有人能告诉我这是怎么回事吗?这种情况是否只发生在有两个或多个类名称相似的项目的情况下?还是其他原因?
我有一个项目,在编译时产生以下错误:
重复'AssemblyVersion'属性
我检查了文件AssemblyInfo.cs,看起来没有重复。
我在MSDN上找到了这篇文章,它解决了一个类似的问题,并按照这篇文章中的建议解决了这个问题。
有人能告诉我这是怎么回事吗?这种情况是否只发生在有两个或多个类名称相似的项目的情况下?还是其他原因?
当前回答
当我改变文件夹结构并尝试推送时,我也遇到了同样的问题。少管所让我先拔,我就拔了。这在旧文件夹和新文件夹中复制了我的源代码,所以在构建时出现了很多复制错误。
只需删除重复的文件夹就可以解决这个问题。
其他回答
当我改变文件夹结构并尝试推送时,我也遇到了同样的问题。少管所让我先拔,我就拔了。这在旧文件夹和新文件夹中复制了我的源代码,所以在构建时出现了很多复制错误。
只需删除重复的文件夹就可以解决这个问题。
我的错误是我还引用了项目中的另一个文件,该文件也包含属性“AssemblyVersion”的值。我从其中一个文件中删除了该属性,现在它正常工作了。
关键是要确保在项目中的任何文件中声明这个值不超过一次。
编辑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
我最近遇到了这种情况,没有对源代码进行任何更改,但在尝试了一些新的项目参考之后。我进入了这样一种状态,即使在恢复了分支中的所有更改之后,这个错误仍然出现。
清理树枝解决了我的问题:
Git clean -xfd
如果您在Azure DevOps上的构建管道中遇到此问题,请尝试将构建操作设置为“Content”,并在AssembyInfo.cs文件属性中将“Copy to Output Directory”设置为“如果更新则复制”。