C# 获得编译时错误 CS0579:重复的“AssemblyFileVersionAttribute”属性

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10590017/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 14:24:45  来源:igfitidea点击:

Getting a compile time error CS0579: Duplicate 'AssemblyFileVersionAttribute' attribute

c#attributesduplicates

提问by

I recently added some copyright information to a set of C# projects (dlls) via the Properties->Application->Assembly Information button. I have several such projects in a single solution. Upon compilation I get error message of the type:

我最近通过 Properties->Application->Assembly Information 按钮向一组 C# 项目 (dll) 添加了一些版权信息。我在一个解决方案中有几个这样的项目。编译后,我收到以下类型的错误消息:

error CS0579: Duplicate 'XXX' attribute

错误 CS0579:重复的“XXX”属性

where 'XXX' is the name of one of the attributes I specified (e.g. AssemblyFileVersionAttribute)

其中“XXX”是我指定的属性之一的名称(例如 AssemblyFileVersionAttribute)

Googling I found that in the case of a class that is derived from the Attribute class, duplicates can be permitted by use of:

谷歌搜索我发现,对于派生自 Attribute 类的类,可以使用以下方法允许重复:

[System.AttributeUsage(System.AttributeTargets.All, AllowMultiple=true)]
class NewAttribute : System.Attribute { }

But in my case, I have added these attributes via the properties dialog and have statements (in AssemblyInfo.cs for each project) such as:

但就我而言,我已经通过属性对话框添加了这些属性,并有语句(在每个项目的 AssemblyInfo.cs 中),例如:

[assembly: AssemblyCompanyAttribute("My Company")]
[assembly: AssemblyProductAttribute("My Product")]
[assembly: AssemblyCopyrightAttribute("? 2012 My Company, All Rights Reserved.")]
[assembly: AssemblyVersionAttribute("13.0.0.0")]
[assembly: AssemblyFileVersionAttribute("1.0.0.0")]

and do not have any manually derived attribute classes I can attach any qualifiers to.

并且没有任何可以附加任何限定符的手动派生属性类。

How do I solve this duplicate issue?

我如何解决这个重复的问题?

采纳答案by rishad2m8

I think you already specified those attributes in Assembly Informationwindow of Project Properties. If you did this, please remove those attributes from Assembly Information.

我认为您已经在Project Properties 的Assembly Information窗口中指定了这些属性。如果您这样做了,请从Assembly Information 中删除这些属性。

回答by Vishnu Sharma

By adding this in .csproj file solved the issue

通过在 .csproj 文件中添加它解决了这个问题

 <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
        <GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
        <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
        <GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
  </PropertyGroup>