When I build my application I get the following error
Error CS0579 Duplicate 'global::System.Runtime.Versioning.TargetFrameworkAttribute' attribute MyUIApp
D:MyUIAppobjDebugnetcoreapp3.1.NETCoreApp,Version=v3.1.AssemblyAttributes.cs 4 Active
The following code is autogenerated in the obj/Debug/netcoreapp3.1 folder
//
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(«.NETCoreApp,Version=v3.1», FrameworkDisplayName = «»)]
I have a project file starting with
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<OutputType>Library</OutputType>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..</SolutionDir>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<RestorePackages>true</RestorePackages>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
<PropertyGroup>
I can work around the issue by commenting out the contents of the file, but not by deleting the file.
asked May 25, 2020 at 7:45
KirstenKirsten
14.3k38 gold badges166 silver badges295 bronze badges
1
I was also getting this error in VS Code and the following fixed it.
I have a project/solution with three projects within in.
- netstandard2.1
- netstandard2.1
- netcoreapp3.1
I added the following line to each of the *.csproj
files within the <PropertyGroup>
section:
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
Full example
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
</Project>
After doing the above you might need to clean /bin
and /obj
folders for each project.
This article pointed me in the right direction though nothing online that I found mentioned the attribute above. I just guessed and it worked!
answered Jun 18, 2020 at 16:51
wsamohtwsamoht
1,5381 gold badge14 silver badges14 bronze badges
6
Add the following two lines to the <PropertyGroup>
. This fixed it for me.
<PropertyGroup>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
</PropertyGroup>
answered Sep 11, 2020 at 19:53
Chuck HardtChuck Hardt
9625 silver badges3 bronze badges
5
The problem was about my folder structure : the test project was in the main project folder. Passing each side by side in the same repo solved the problem
MyProject
src/MyProject.csproj
tests/MyTestProject.csproj
Taken from Github issue : https://github.com/dotnet/core/issues/4837
answered Jun 17, 2020 at 10:02
CladooCladoo
5885 silver badges19 bronze badges
6
So i did encounter the same on a .NET 4.7 based solution, spent hours, only to find out a colleague of mine did include the obj and bin folders in the project!
excluding them fixed the issue and that error went away.
hope this save someone a couple of hours.
answered Dec 3, 2021 at 18:18
azakiazaki
3963 silver badges5 bronze badges
4
I fixed this by deleting the obj and bin folders in each project directory. I then cleaned the solution and rebuilt. The rebuild succeeded.
answered Oct 7, 2020 at 1:15
1
You just need to exclude the obj
folder from the project/solution.
answered Aug 4, 2021 at 17:26
Joe ShakelyJoe Shakely
4656 silver badges8 bronze badges
5
I was facing the same issue in my asp.net core 3.1
application right after I add the xUnit
project to the solution. Ultimately, the main issue was because of that I selected the check box Place solution and project in the same directory as shown in the preceding image.
This should work in normal cases, and you will just consider this root directory as the Git repository (the .sln
file and the .csproj
will be in the same folder). But you will not be able to add a new project to this directory as you will get the error «Error CS0579 Duplicate ‘global::System.Runtime.Versioning.TargetFrameworkAttribute'». So, to fix this error, we just have to follow the preceding steps.
- Create a folder with the same name in the
.sln
file - Move all the project-related files to that directory
- Open your
.sln
file with any code editor - Edit the Project references.
- Make sure that your
.sln
file is in the root directory
This is how your project file references may look like now.
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApplication2", "WebApplication2WebApplication2.csproj", "{027937D8-D0E6-45A4-8846-C2E28DA102E6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApplication2.Tests", "WebApplication2.TestsWebApplication2.Tests.csproj", "{AD4C6C31-F617-4E76-985A-32B0E3104004}"
EndProject
That’s it. Just reload your solution and happy coding!.
answered Nov 19, 2020 at 12:15
Sibeesh VenuSibeesh Venu
17k11 gold badges93 silver badges136 bronze badges
0
Try to delete obj folder from Project, delete it from SolutionExplorer instead of WindowExplorer.
answered May 12, 2022 at 2:34
2
I encountered that issue, what I did is I deleted the .NETCoreApp,Version=v3.1.AssemblyAttributes.cs and then I ran VSCode as an administrator.
answered May 28, 2020 at 8:27
I had this when my folder structure got messed up. I’m using Visual Studio 2019 and switched branches that has different folder structure. Some folders got added up in the file explorer and didn’t get deleted even if I switched branches. All I did was to delete those folders that weren’t part of my current branch and it worked.
answered Mar 27, 2021 at 0:43
RaffyRaffy
3951 gold badge6 silver badges11 bronze badges
1
I am having the same problem. As far as I can tell, the flag should prevent the auto-generation of assembly info. However, I can see this file in my obj directory:
.NETStandard,Version=v2.1.AssemblyAttributes.cs
It only contains the target version attribute. Maybe there is some other way of suppressing this attribute?
It seems like this might be a regression in .NET core 3.1.300. I was building with .NET core 3.1.200 and I didn’t see this issue until I upgraded.
answered May 26, 2020 at 11:57
2
I experienced this on a build pipeline in Azure Devops. I was using a local agent to run the pipeline on (my own machine). It appears that there was code in the working directory that was causing this conflict, and by default, the agent doesn’t clean the working directory before starting the pipeline process.
The fix was to delete the contents of the working directory on the agent. I did this by selecting the option to clean the working directory:
answered Aug 31, 2020 at 21:13
ajbeavenajbeaven
9,07513 gold badges79 silver badges120 bronze badges
In my case the culprit was my test project so I had to go to my test folder > obj > Debug/net6.0 > .NETCoreApp,Version=v6.0.AssemblyAttributes.cs
and then commented this line
[assembly:global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
answered Jul 15, 2022 at 10:22
Sven.higSven.hig
4,4482 gold badges7 silver badges18 bronze badges
This error can also happen if you accidentally copied an project file into another projects folder.
answered Dec 18, 2020 at 6:44
JohanJohan
1392 silver badges2 bronze badges
I had this kind of Errors in my Blazor Server project when I tried to add .NET Standard Class Library project in Visual Studio 2019.
Errors:
To fix this i tried following ways.
.csproj file Before
.csproj file After
answered Sep 30, 2021 at 18:31
1
in my case (.NET 6.0
);
I just exclude the Properties
folder from the project/solution.
answered Apr 16, 2022 at 8:18
AminRostamiAminRostami
2,5363 gold badges24 silver badges45 bronze badges
From the many different kind of answers, it’s clear that there could be different reasons for the same issue. In my case the solution definition file was the cause. I decided to delete and create a clean solution file.
- Delete the .sln file
- Create a blank .sln file, in the root of your project/solution:
dotnet new sln
- For every C# project file in your solution, add it with the following command, for example:
dotnet add MyApplication.csproj
and for example:
dotnet add CustomPackages/MyLibrary.csproj
Then to make sure all previous build artefacts are cleaned up
dotnet clean
answered May 24, 2022 at 13:51
Superman.LopezSuperman.Lopez
1,1061 gold badge10 silver badges36 bronze badges
Encountered this issue when working with AWS Lambda. Turns out I was switching branches, and some auto-generated folders did not get cleared after switching to new branch, and dotnet was picking them up for some reason. The easiest solution is to delete all local project folders, and check out clean version of the code again.
answered Jan 4 at 18:18
Eternal21Eternal21
3,8822 gold badges43 silver badges58 bronze badges
I commented out the offending attribute
// obj/Debug/netcoreapp3.1/.NETCoreApp,Version=v3.1.AssemblyAttributes.cs
using System;
using System.Reflection;
//[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v3.1", FrameworkDisplayName = "")]
answered Aug 6, 2020 at 14:55
1
DELETE [assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
Suraj Rao
29.3k11 gold badges96 silver badges103 bronze badges
answered Sep 2, 2022 at 12:09
I was able to solve this issue by getting a new clone of the project.
answered Apr 28, 2021 at 5:08
Hello, I am working on a SDK where we have multiple build targets. I have been running into an issue where each of the targets seems to be building assembly attributes when I have explicitly turned them off with
<TargetFramework>netstandard2.0</TargetFramework> <GeneratePackageOnBuild>true</GeneratePackageOnBuild> <AssemblyName>Dropbox.Api</AssemblyName> <RootNamespace>Dropbox.Api</RootNamespace> <GenerateAssemblyInfo>false</GenerateAssemblyInfo> <GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> <GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute> <GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute> <GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> <GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute> <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> <GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
In the main property group of every csproj file
Here is the errors I am seeing:
net45objDebug.NETFramework,Version=v4.5.AssemblyAttributes.cs(4,12): error CS0579: Duplicate 'global::System.Runtime. Versioning.TargetFrameworkAttribute' attribute [dropbox-sdk-dotnetdropbox-sdk-dotnetDropbox.Api Dropbox.Api.NetStandard.csproj] net45objRelease.NETFramework,Version=v4.5.AssemblyAttributes.cs(4,12): error CS0579: Duplicate 'global::System.Runtim e.Versioning.TargetFrameworkAttribute' attribute [dropbox-sdk-dotnetdropbox-sdk-dotnetDropbox.Ap iDropbox.Api.NetStandard.csproj] portable40objDebug.NETPortable,Version=v4.0,Profile=Profile344.AssemblyAttributes.cs(4,12): error CS0579: Duplicate ' global::System.Runtime.Versioning.TargetFrameworkAttribute' attribute [dropbox-sdk-dotnetdropbox- sdk-dotnetDropbox.ApiDropbox.Api.NetStandard.csproj] portable40objRelease.NETPortable,Version=v4.0,Profile=Profile344.AssemblyAttributes.cs(4,12): error CS0579: Duplicate 'global::System.Runtime.Versioning.TargetFrameworkAttribute' attribute [dropbox-sdk-dotnetdropbo x-sdk-dotnetDropbox.ApiDropbox.Api.NetStandard.csproj] portableobjDebug.NETPortable,Version=v4.5,Profile=Profile111.AssemblyAttributes.cs(4,12): error CS0579: Duplicate 'gl obal::System.Runtime.Versioning.TargetFrameworkAttribute' attribute [dropbox-sdk-dotnetdropbox-sd k-dotnetDropbox.ApiDropbox.Api.NetStandard.csproj] portableobjRelease.NETPortable,Version=v4.5,Profile=Profile111.AssemblyAttributes.cs(4,12): error CS0579: Duplicate ' global::System.Runtime.Versioning.TargetFrameworkAttribute' attribute [dropbox-sdk-dotnetdropbox- sdk-dotnetDropbox.ApiDropbox.Api.NetStandard.csproj] objReleasenetstandard2.0.NETStandard,Version=v2.0.AssemblyAttributes.cs(4,12): error CS0579: Duplicate 'global::Syst em.Runtime.Versioning.TargetFrameworkAttribute' attribute [dropbox-sdk-dotnetdropbox-sdk-dotnetD ropbox.ApiDropbox.Api.NetStandard.csproj]
I am not sure if I am generating this incorrectly or if there is another way to disable this error.
For more information, I am working on the Dropbox SDK
Содержание
- Duplicate Targetframework attribute #9781
- Comments
- Steps to reproduce
- Expected behavior
- Actual behavior
- Environment data
- CS0579 Duplicate Attribute Error with .NET Core
- Problem description
- tl;dr Solution
- Details
- error CS0579: Duplicate ‘global::System.Runtime.Versioning.TargetFrameworkAttribute’ attribute #12297
- Comments
- Ошибка CS0579: дубликат global::System.Runtime.Versioning.TargetFrameworkAttribute
- 18 ответов
- dotnet build results in error CS0579 duplicate attributes with AssemblyVersionAttribute (and others) specified #7207
- Comments
- Steps to reproduce
- Expected behavior
- Actual behavior
- Environment data
Duplicate Targetframework attribute #9781
I have similary problems with that issue.
It started when i run npm install . Packages installation finished with error then dotnet build got error
I tried deleting the obj and use dotnet clean . It is not helped me.
Steps to reproduce
Expected behavior
Actual behavior
Environment data
dotnet —info output:
The text was updated successfully, but these errors were encountered:
Please, provide us with more details. What kind of project are you creating? Can you give us a full repro for this? The issue you referenced has been closed for months. Please provide either a repo on github where we can repro this or detailed repro steps. The steps you provided above are not sufficient.
My project very old. The project was successfully compiled before use npm install .
I notice that in project root folder create autogenerate file .NETCoreApp,Version=v2.1.AssemblyAttributes.cs . If I delete it the compilation is successful but then created again
I am not sure why npm install would interfere with this at all. Do you have any customization in your project that might be causing this?
Could you share with us a binlog? dotnet build /bl, should generate a .binlog file that you could share with us. Do notice that if you do, the binlog logs secrets and things like that, so make sure you don’t have any in your build before sharing.
Without a binlog or a repro we can reproduce ourselves, there isn’t much we can do.
You can try setting false in your project, so see if the file stops being generated and your build succeeds.
No, i think that no. Before the advent of have this error i added one new npm package in my project.
Okay, can I leave a direct link here?
Without a binlog or a repro we can reproduce ourselves, there isn’t much we can do.
Yes, this help me
You can try setting false in your project, so see if the file stops being generated and your build succeeds.
Yes, you can leave a link here.
So, setting the property above fixed the issue for you?
Источник
CS0579 Duplicate Attribute Error with .NET Core
I’ll leave the below for posterity, but recently I came across the real reason for the error. In this issue it was pointed out that your .net core solutions have to be structured in a particular way. Specifically, make sure that you do not create projects in the same directory as your main project.
Problem description
I recently started working on my first .NET Core project and quickly ran into a problem. After adding a class library project, the second time I ran dotnet run I received the following errors:
error CS0579: Duplicate ‘System.Reflection.AssemblyCompanyAttribute’ attribute error CS0579: Duplicate ‘System.Reflection.AssemblyConfigurationAttribute’ attribute error CS0579: Duplicate ‘System.Reflection.AssemblyFileVersionAttribute’ attribute error CS0579: Duplicate ‘System.Reflection.AssemblyInformationalVersionAttribute’ attribute error CS0579: Duplicate ‘System.Reflection.AssemblyProductAttribute’ attribute error CS0579: Duplicate ‘System.Reflection.AssemblyTitleAttribute’ attribute error CS0579: Duplicate ‘System.Reflection.AssemblyVersionAttribute’ attribute
tl;dr Solution
My Google-fu revealed the solution buried in a GitHub issue thread. Add the following line to your *.csproj files:
As the name indicates, this will prevent the build process from generating the AssemblyInfo.cs file in project obj directories, thus preventing the duplicate attribute conflict.
Details
Disclaimer: I am far from a .NET expert so there is probably more to this story.
Источник
error CS0579: Duplicate ‘global::System.Runtime.Versioning.TargetFrameworkAttribute’ attribute #12297
Hello, I am working on a SDK where we have multiple build targets. I have been running into an issue where each of the targets seems to be building assembly attributes when I have explicitly turned them off with
In the main property group of every csproj file
Here is the errors I am seeing:
net45objDebug.NETFramework,Version=v4.5.AssemblyAttributes.cs(4,12): error CS0579: Duplicate ‘global::System.Runtime. Versioning.TargetFrameworkAttribute’ attribute [dropbox-sdk-dotnetdropbox-sdk-dotnetDropbox.Api Dropbox.Api.NetStandard.csproj] net45objRelease.NETFramework,Version=v4.5.AssemblyAttributes.cs(4,12): error CS0579: Duplicate ‘global::System.Runtim e.Versioning.TargetFrameworkAttribute’ attribute [dropbox-sdk-dotnetdropbox-sdk-dotnetDropbox.Ap iDropbox.Api.NetStandard.csproj] portable40objDebug.NETPortable,Version=v4.0,Profile=Profile344.AssemblyAttributes.cs(4,12): error CS0579: Duplicate ‘ global::System.Runtime.Versioning.TargetFrameworkAttribute’ attribute [dropbox-sdk-dotnetdropbox- sdk-dotnetDropbox.ApiDropbox.Api.NetStandard.csproj] portable40objRelease.NETPortable,Version=v4.0,Profile=Profile344.AssemblyAttributes.cs(4,12): error CS0579: Duplicate ‘global::System.Runtime.Versioning.TargetFrameworkAttribute’ attribute [dropbox-sdk-dotnetdropbo x-sdk-dotnetDropbox.ApiDropbox.Api.NetStandard.csproj] portableobjDebug.NETPortable,Version=v4.5,Profile=Profile111.AssemblyAttributes.cs(4,12): error CS0579: Duplicate ‘gl obal::System.Runtime.Versioning.TargetFrameworkAttribute’ attribute [dropbox-sdk-dotnetdropbox-sd k-dotnetDropbox.ApiDropbox.Api.NetStandard.csproj] portableobjRelease.NETPortable,Version=v4.5,Profile=Profile111.AssemblyAttributes.cs(4,12): error CS0579: Duplicate ‘ global::System.Runtime.Versioning.TargetFrameworkAttribute’ attribute [dropbox-sdk-dotnetdropbox- sdk-dotnetDropbox.ApiDropbox.Api.NetStandard.csproj] objReleasenetstandard2.0.NETStandard,Version=v2.0.AssemblyAttributes.cs(4,12): error CS0579: Duplicate ‘global::Syst em.Runtime.Versioning.TargetFrameworkAttribute’ attribute [dropbox-sdk-dotnetdropbox-sdk-dotnetD ropbox.ApiDropbox.Api.NetStandard.csproj]
I am not sure if I am generating this incorrectly or if there is another way to disable this error.
For more information, I am working on the Dropbox SDK
The text was updated successfully, but these errors were encountered:
Источник
Ошибка CS0579: дубликат global::System.Runtime.Versioning.TargetFrameworkAttribute
Когда я создаю свое приложение, я получаю следующую ошибку
Следующий код автоматически создается в папке obj/Debug/netcoreapp3.1.
// используя System; using System.Reflection; [сборка: global::System.Runtime.Versioning.TargetFrameworkAttribute(«.NETCoreApp,Version=v3.1», FrameworkDisplayName = «»)]
У меня есть файл проекта, начинающийся с
Я могу обойти проблему, закомментировав содержимое файла, но не удалив файл.
18 ответов
Я также получал эту ошибку в VS Code, и следующее исправило ее.
У меня есть проект / решение с тремя проектами внутри.
- netstandard2.1
- netstandard2.1
- netcoreapp3.1
Я добавил следующую строку к каждому из *.csproj файлы:
Эта статья указала мне в правильном направлении, хотя в Интернете ничего не упоминалось об этом атрибуте. Я просто догадался, и это сработало!
Добавьте следующие две строки в
. Это исправило это для меня.
Я решил проблему способом, описанным в проблеме Github: https://github.com/dotnet/core/issues/4837
Проблема заключалась в структуре моей папки: тестовый проект находился в основной папке проекта. Передача каждого бок о бок в одном репо решила проблему
Так что я столкнулся с тем же самым в решении на основе .NET 4.7, потратил часы, только чтобы узнать, что мой коллега действительно включил папки obj и bin в проект! их исключение устранило проблему, и эта ошибка исчезла.
надеюсь, это сэкономит кому-то пару часов.
Я исправил это, удалив папки obj и bin в каждом каталоге проекта. Затем я очистил раствор и восстановил. Восстановление выполнено успешно.
Вам просто нужно исключить obj папку из проекта / решения.
Я столкнулся с той же проблемой в моем asp.net core 3.1 приложение сразу после добавления xUnit проект к решению. В конечном итоге основная проблема заключалась в том, что я установил флажок Поместить решение и проект в тот же каталог, что и на предыдущем изображении.
Это должно работать в обычных случаях, и вы просто будете рассматривать этот корневой каталог как репозиторий Git ( .sln файл и .csproj будет в той же папке). Но вы не сможете добавить новый проект в этот каталог, так как вы получите ошибку «Ошибка CS0579 Duplicate ‘global::System.Runtime.Versioning.TargetFrameworkAttribute’». Итак, чтобы исправить эту ошибку, нам просто нужно выполнить предыдущие шаги.
- Создайте папку с таким же именем в .sln файл
- Переместите все файлы, связанные с проектом, в этот каталог
- Откройте свой .sln файл любым редактором кода
- Отредактируйте ссылки на проект.
- Убедитесь, что ваш .sln файл находится в корневом каталоге
Вот как теперь могут выглядеть ссылки на файлы вашего проекта.
Вот и все. Просто перезагрузите свое решение и удачного кодирования!.
Источник
dotnet build results in error CS0579 duplicate attributes with AssemblyVersionAttribute (and others) specified #7207
Building a library project fails with error CS0579 (duplicate attribute) with library projects with AssemblyVersionAttribute (or other assembly attributes) specified.
- Adding (for example) false to csproj fixes
Steps to reproduce
- dotnet new -t lib
- insert [assembly: System.Reflection.AssemblyVersion(«0.1.0.0»)] into Library.cs
- dotnet restore
- dotnet build
Expected behavior
Build is successful
Actual behavior
Environment data
The text was updated successfully, but these errors were encountered:
Setting GenerateAssemblyInfo property to false fixes for all attributes:
@frankbuckley Im glad the switches fix the issue. Do you have thoughts on how the experience should change?
(I’m not sure why I thought this did not happen with exe projects. I have just tried again and it does.)
I hit the issue porting existing code from existing PCL projects by creating a new netstandard/core library ( dotnet new -t lib ) and copying sources (including, as it happened, PropertiesAssemblyInfo.cs).
If traditional assembly attributes are being somehow deprecated in the new csproj model, I think the error message should be more explanatory. I was left wondering «what duplicates?» The error message should state something like assembly attributes are generated from the project file, hence the duplication.
That said, if assembly attributes are defined in code files, could they not simply take precedence and prevent the (duplicated) generation of assembly attributes by the build system?
It is particular confusing that these are auto-generated when there are no properties in the csproj file specifying version numbers (or company, etc.) They seem to appear from nowhere!
Источник
UPDATED: 2020-12-23
I’ll leave the below for posterity, but recently I came across the real reason for the error. In this issue it was pointed out that your .net core solutions have to be structured in a particular way. Specifically, make sure that you do not create projects in the same directory as your main project.
Problem description
I recently started working on my first .NET Core project and quickly ran into a problem. After adding a class library project, the second time I ran dotnet run
I received the following errors:
error CS0579: Duplicate ‘System.Reflection.AssemblyCompanyAttribute’ attribute
error CS0579: Duplicate ‘System.Reflection.AssemblyConfigurationAttribute’ attribute
error CS0579: Duplicate ‘System.Reflection.AssemblyFileVersionAttribute’ attribute
error CS0579: Duplicate ‘System.Reflection.AssemblyInformationalVersionAttribute’ attribute
error CS0579: Duplicate ‘System.Reflection.AssemblyProductAttribute’ attribute
error CS0579: Duplicate ‘System.Reflection.AssemblyTitleAttribute’ attribute
error CS0579: Duplicate ‘System.Reflection.AssemblyVersionAttribute’ attribute
tl;dr Solution
My Google-fu revealed the solution buried in a GitHub issue thread. Add the following line to your *.csproj
files:
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
As the name indicates, this will prevent the build process from generating the AssemblyInfo.cs file in project obj
directories, thus preventing the duplicate attribute conflict.
Details
Disclaimer: I am far from a .NET expert so there is probably more to this story.
The error is a result of the build process generating AssemblyInfo.cs
files in each project obj
directory. This file exists to provide MSBuild metadata about the resulting assembly that can be attached to the build artifact and utilized by anyone who wants such information. You can see your assembly info in Windows by selecting your build artifact, right click -> properties. The following shows the results with GenerateAssemblyInfo set to false. As you can see, the metadata is set to default values.
It’s not clear why the default .csproj
file generated by dotnet new
results in this behavior. The closest I came across was a mention of the philosophy to keep the file as terse as possible. Of course, I’m completely in support of this as .csproj
tends to be a dense mess in Visual Studio. However, this particular scenario puts the onus on the developer to edit the file to eliminate an error which is almost guaranteed to occur in a project of any complexity. A better design decision would have probably been to default to not generating AssemblyInfo.cs
.
I got the following errors today while working on a new project:
Error CS0579 Duplicate ‘System.Reflection.AssemblyVersionAttribute’ attribute MyAzureFunction C:ReposTestMyAzureFunctionobjDebugnet6.0MyAzureFunction.AssemblyInfo.cs 20 Active
Error CS0579 Duplicate ‘global::System.Runtime.Versioning.TargetFrameworkAttribute’ attribute MyAzureFunction C:ReposTestMyAzureFunctionobjDebugnet6.0.NETCoreApp,Version=v6.0.AssemblyAttributes.cs 4 Active
Error CS0579 Duplicate ‘System.Reflection.AssemblyCompanyAttribute’ attribute MyAzureFunction C:ReposTestMyAzureFunctionobjDebugnet6.0MyAzureFunction.AssemblyInfo.cs 14 Active
Error CS0579 Duplicate ‘System.Reflection.AssemblyConfigurationAttribute’ attribute MyAzureFunction C:ReposTestMyAzureFunctionobjDebugnet6.0MyAzureFunction.AssemblyInfo.cs 15 Active
Error CS0579 Duplicate ‘System.Reflection.AssemblyFileVersionAttribute’ attribute MyAzureFunction C:ReposTestMyAzureFunctionobjDebugnet6.0MyAzureFunction.AssemblyInfo.cs 16 Active
Error CS0579 Duplicate ‘System.Reflection.AssemblyInformationalVersionAttribute’ attribute MyAzureFunction C:ReposTestMyAzureFunctionobjDebugnet6.0MyAzureFunction.AssemblyInfo.cs 17 Active
Error CS0579 Duplicate ‘System.Reflection.AssemblyProductAttribute’ attribute MyAzureFunction C:ReposTestMyAzureFunctionobjDebugnet6.0MyAzureFunction.AssemblyInfo.cs 18 Active
Error CS0579 Duplicate ‘System.Reflection.AssemblyTitleAttribute’ attribute MyAzureFunction C:ReposTestMyAzureFunctionobjDebugnet6.0MyAzureFunction.AssemblyInfo.cs 19 Active
and it looked like the following in the error list:
I figured out that I had created a project within my project by mistake. I had two projects «MyAzureFunction» and «YahooFinanceApi». The project structure looked like the following:
BaseFolder
MyAzureFunction
MyAzureFunction.csproj
YahooFinanceApi
YahooFinanceApi.Csjproj
solution.sln
What solved the above for me was changing the above to the following:
BaseFolder
MyAzureFunction
MyAzureFunction.csproj
YahooFinanceApi
YahooFinanceApi.csproj
solution.sln
This way the YahooFinanceApi project was not built within the MyAzureFunction project. For some reason this made the MyAzureFunction project fail with the duplicate error when built.
I hope this helps someone out there
Dung Do Tien May 12 2021 824
I have a project web, be developing with Asp.net Core 3.1.
Everything work well but one day I got the latest code from Git and builds I got an error Duplicate ‘global::System.Runtime.Versioning.TargetFrameworkAttribute’ attribute.
Error CS0579 Duplicate 'global::System.Runtime.Versioning.TargetFrameworkAttribute' attribute
D:GameOBJobjDebugnetcoreapp3.1.NETCoreApp,Version=v3.1.AssemblyAttributes.cs
The following code is autogenerated in the obj/Debug/netcoreapp3.1 folder
// using System; using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v3.1", FrameworkDisplayName = "")]
I checked all project versions but nothing change. I also tried to clear and rebuild all solutions but it still not work for me.
Thanks for any suggestion.
Have 2 answer(s) found.
-
Watcharapong Jakkawannorasing
May 12 2021Add the following two lines to the
<PropertyGroup>
.<PropertyGroup> <GenerateAssemblyInfo>false</GenerateAssemblyInfo> <GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute> </PropertyGroup>
I try it and fixed it for me.
-
I got the same error in VS2019, to resolve this issue you can open
.csproj
and add line code below inside tag<PropertyGroup>
:<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
And then save this file, clear and rebuild project.
I hope it helpful for you.
When I build my application I get the following error
Error CS0579 Duplicate 'global::System.Runtime.Versioning.TargetFrameworkAttribute' attribute MyUIApp
D:MyUIAppobjDebugnetcoreapp3.1.NETCoreApp,Version=v3.1.AssemblyAttributes.cs 4 Active
The following code is autogenerated in the obj/Debug/netcoreapp3.1 folder
//
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(«.NETCoreApp,Version=v3.1», FrameworkDisplayName = «»)]
I have a project file starting with
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<OutputType>Library</OutputType>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..</SolutionDir>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<RestorePackages>true</RestorePackages>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
<PropertyGroup>
I can work around the issue by commenting out the contents of the file, but not by deleting the file.
15 Answers
I was also getting this error in VS Code and the following fixed it.
I have a project/solution with three projects within in.
- netstandard2.1
- netstandard2.1
- netcoreapp3.1
I added the following line to each of the *.csproj
files within the <PropertyGroup>
section:
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
Full example
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
</Project>
After doing the above you might need to clean /bin
and /obj
folders for each project.
This article pointed me in the right direction though nothing online that I found mentioned the attribute above. I just guessed and it worked!
Add the following two lines to the <PropertyGroup>
. This fixed it for me.
<PropertyGroup>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
</PropertyGroup>
The problem was about my folder structure : the test project was in the main project folder. Passing each side by side in the same repo solved the problem
MyProject
src/MyProject.csproj
tests/MyTestProject.csproj
Taken from Github issue : https://github.com/dotnet/core/issues/4837
I fixed this by deleting the obj and bin folders in each project directory. I then cleaned the solution and rebuilt. The rebuild succeeded.
You just need to exclude the obj
folder from the project/solution.
I was facing the same issue in my asp.net core 3.1
application right after I add the xUnit
project to the solution. Ultimately, the main issue was because of that I selected the check box Place solution and project in the same directory as shown in the preceding image.
This should work in normal cases, and you will just consider this root directory as the Git repository (the .sln
file and the .csproj
will be in the same folder). But you will not be able to add a new project to this directory as you will get the error «Error CS0579 Duplicate ‘global::System.Runtime.Versioning.TargetFrameworkAttribute'». So, to fix this error, we just have to follow the preceding steps.
- Create a folder with the same name in the
.sln
file - Move all the project-related files to that directory
- Open your
.sln
file with any code editor - Edit the Project references.
- Make sure that your
.sln
file is in the root directory
This is how your project file references may look like now.
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApplication2", "WebApplication2WebApplication2.csproj", "{027937D8-D0E6-45A4-8846-C2E28DA102E6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApplication2.Tests", "WebApplication2.TestsWebApplication2.Tests.csproj", "{AD4C6C31-F617-4E76-985A-32B0E3104004}"
EndProject
That’s it. Just reload your solution and happy coding!.
I encountered that issue, what I did is I deleted the .NETCoreApp,Version=v3.1.AssemblyAttributes.cs and then I ran VSCode as an administrator.
So i did encounter the same on a .NET 4.7 based solution, spent hours, only to find out a colleague of mine did include the obj and bin folders in the project!
excluding them fixed the issue and that error went away.
hope this save someone a couple of hours.
I am having the same problem. As far as I can tell, the flag should prevent the auto-generation of assembly info. However, I can see this file in my obj directory:
.NETStandard,Version=v2.1.AssemblyAttributes.cs
It only contains the target version attribute. Maybe there is some other way of suppressing this attribute?
It seems like this might be a regression in .NET core 3.1.300. I was building with .NET core 3.1.200 and I didn’t see this issue until I upgraded.
I experienced this on a build pipeline in Azure Devops. I was using a local agent to run the pipeline on (my own machine). It appears that there was code in the working directory that was causing this conflict, and by default, the agent doesn’t clean the working directory before starting the pipeline process.
The fix was to delete the contents of the working directory on the agent. I did this by selecting the option to clean the working directory:
I had this when my folder structure got messed up. I’m using Visual Studio 2019 and switched branches that has different folder structure. Some folders got added up in the file explorer and didn’t get deleted even if I switched branches. All I did was to delete those folders that weren’t part of my current branch and it worked.
This error can also happen if you accidentally copied an project file into another projects folder.
I had this kind of Errors in my Blazor Server project when I tried to add .NET Standard Class Library project in Visual Studio 2019.
Errors:
To fix this i tried following ways.
.csproj file Before
.csproj file After
I commented out the offending attribute
// obj/Debug/netcoreapp3.1/.NETCoreApp,Version=v3.1.AssemblyAttributes.cs
using System;
using System.Reflection;
//[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v3.1", FrameworkDisplayName = "")]
I was able to solve this issue by getting a new clone of the project.
- Remove From My Forums
-
Question
-
I have created a new GAT project. Removed all the existing projects which are shown by default in the Project.
I am adding a new project under Templates/Solutions/Projects/MyClassProject
This folder has a file Properties/AssemblyInfo.cs. When am compiling my solution I ma getting the following compile errors
Can someone help me understand why is this compiler errors seen? This AssemblyInfo.cs if my GAT project’s file and it seems to be clashing with Templates/Solutions/Projects/MyClassProject/Properties/AssemblyInfo.cs file.
C:TempForDeleteRndTest_GuidancePackageMyApplicationPackageMyApplicationPackagePropertiesAssemblyInfo.cs(31,12): error CS0579: Duplicate ‘AssemblyVersion’ attribute
C:TempForDeleteRndTest_GuidancePackageMyApplicationPackageMyApplicationPackagePropertiesAssemblyInfo.cs(20,12): error CS0579: Duplicate ‘ComVisible’ attribute
C:TempForDeleteRndTest_GuidancePackageMyApplicationPackageMyApplicationPackagePropertiesAssemblyInfo.cs(15,12): error CS0579: Duplicate ‘AssemblyCulture’ attribute
C:TempForDeleteRndTest_GuidancePackageMyApplicationPackageMyApplicationPackagePropertiesAssemblyInfo.cs(14,12): error CS0579: Duplicate ‘AssemblyTrademark’ attribute
C:TempForDeleteRndTest_GuidancePackageMyApplicationPackageMyApplicationPackagePropertiesAssemblyInfo.cs(13,12): error CS0579: Duplicate ‘AssemblyCopyright’ attribute
C:TempForDeleteRndTest_GuidancePackageMyApplicationPackageMyApplicationPackagePropertiesAssemblyInfo.cs(12,12): error CS0579: Duplicate ‘AssemblyProduct’ attribute
C:TempForDeleteRndTest_GuidancePackageMyApplicationPackageMyApplicationPackagePropertiesAssemblyInfo.cs(11,12): error CS0579: Duplicate ‘AssemblyCompany’ attribute
C:TempForDeleteRndTest_GuidancePackageMyApplicationPackageMyApplicationPackagePropertiesAssemblyInfo.cs(10,12): error CS0579: Duplicate ‘AssemblyConfiguration’ attribute
C:TempForDeleteRndTest_GuidancePackageMyApplicationPackageMyApplicationPackagePropertiesAssemblyInfo.cs(9,12): error CS0579: Duplicate ‘AssemblyDescription’ attribute
C:TempForDeleteRndTest_GuidancePackageMyApplicationPackageMyApplicationPackagePropertiesAssemblyInfo.cs(8,12): error CS0579: Duplicate ‘AssemblyTitle’ attribute
Answers
-
This is because you haven’t marked the .cs files you added as content files. You need to make sure the .cs files you add to the «Templates» folder are properly marked as «Build Action=Content» and «Copy To Output Directory=Copy If Newer» so they don’t get compiled with your solution (and classes don’t clash).
In GAT, there is a recipe for automating this setting, if you right-click on the «Templates» folder you should see it, I just don’t remember the exact name for it right now, sorry.
-vga.
-
When you right click on the «Templates» folder of your guidance package project you should get a menu option named «Set Content Files Build Properties», this is the recipe that will automatically set proper build properties for all the content files within that folder. If this option doesn’t appear please make sure that GAT is enabled for the solution you’re working on (go to Tools->Guidance Package Manager->Enable/Disable Packages and make sure Guidance Package Development is checked).
If you want to do this manually, you need to go to each file located within «Templates» folder, look at its properties (press F4) and set its «Build Action» property to «Content» and its «Copy To Output Directoy» as «Copy if newer».
HTH,
-vga.