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

重复'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

其他回答

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

编辑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

当我尝试在AssemblyInfo.cs中添加GitVersion工具来更新我的版本时,我遇到了同样的情况。使用VS2017和。net Core项目。所以我只是混合了两个世界。我的AssemblyInfo.cs只包含由GitVersion工具生成的版本信息,我的csproj包含其余的东西。请注意,我不使用<GenerateAssemblyInfo>false</GenerateAssemblyInfo>我只使用与版本相关的属性(见下面)。更多详细信息,这里是AssemblyInfo属性。

AssemblyInfo.cs

[assembly: AssemblyVersion("0.2.1.0")]
[assembly: AssemblyFileVersion("0.2.1.0")]
[assembly: AssemblyInformationalVersion("0.2.1+13.Branch.master.Sha.119c35af0f529e92e0f75a5e6d8373912d457818")]

我的。Csproj包含所有与其他程序集属性相关的属性:

<PropertyGroup>
   ...
  <Company>SOME Company </Company>
  <Authors>Some Authors</Authors>
  <Product>SOME Product</Product>
   ...
  <GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
  <GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
  <GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
</PropertyGroup>

这个问题是VS 2017特有的参考冲突。

我通过在AssemblyInfo.cs中注释掉第7 -14行以及页面底部的程序集版本代码来解决了同样的错误

它删除了所有重复的引用,项目能够重新构建。