我有一个项目,在编译时产生以下错误:
重复'AssemblyVersion'属性
我检查了文件AssemblyInfo.cs,看起来没有重复。
我在MSDN上找到了这篇文章,它解决了一个类似的问题,并按照这篇文章中的建议解决了这个问题。
有人能告诉我这是怎么回事吗?这种情况是否只发生在有两个或多个类名称相似的项目的情况下?还是其他原因?
我有一个项目,在编译时产生以下错误:
重复'AssemblyVersion'属性
我检查了文件AssemblyInfo.cs,看起来没有重复。
我在MSDN上找到了这篇文章,它解决了一个类似的问题,并按照这篇文章中的建议解决了这个问题。
有人能告诉我这是怎么回事吗?这种情况是否只发生在有两个或多个类名称相似的项目的情况下?还是其他原因?
当前回答
如果我在Visual Studio 2017中编译项目,然后尝试用. net Core用命令行命令“dotnet run”重建并运行它,通常会发生这种情况。
简单地删除所有“bin”和“obj”文件夹——包括在“ClientApp”内部和直接在项目文件夹中——允许. net Core命令“dotnet run”重新构建并成功运行。
其他回答
我一直在这个问题上挣扎,但我的问题很容易解决。
我已经将OBJ文件夹复制到“OBJ___”名称来做一些编译测试。
所以,我不知道为什么,这个文件夹也被编译,创建程序集属性副本。
我只是删除了“OBJ___”文件夹,可以成功编译。
当我尝试在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>
在将旧项目转换为. net Core时,现在可以在项目本身设置AssemblyInfo.cs中的大部分信息。打开项目属性并选择Package选项卡以查看新的设置。
埃里克·l·安德森的帖子 “复制”System.Reflection。AssemblyCompanyAttribute ' attribute"描述了3个选项:
从AssemblyInfo.cs文件中删除冲突项, 完全删除文件或 禁用GenerateAssemblyInfo(在Serge Semenov的另一个回答中建议)
这里的项目中必须已经有一个AssemblyInfo.cs文件:
解决: —删除任意一个AssemblyInfo.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