Duplicate 'System.Reflection.AssemblyCompanyAttribute' attribute in new Azure Functions project

Viewed 1850

I get many error messages when I want to deploy my new project to Azure.

AssemblyInfo.cs:

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Reflection;

[assembly: System.Reflection.AssemblyCompanyAttribute("Newfunctions")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("Newfunctions")]
[assembly: System.Reflection.AssemblyTitleAttribute("Newfunctions")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

// Generated by the MSBuild WriteCodeFragment class.

Error messages:

Duplicate 'System.Reflection.AssemblyCompanyAttribute' attribute [Newfunctions]
Duplicate 'System.Reflection.AssemblyConfigurationAttribute' attribute [Newfunctions]
Duplicate 'System.Reflection.AssemblyFileVersionAttribute' attribute [Newfunctions]
Duplicate 'System.Reflection.AssemblyInformationalVersionAttribute' attribute [Newfunctions]
Duplicate 'System.Reflection.AssemblyProductAttribute' attribute [Newfunctions]
Duplicate 'System.Reflection.AssemblyTitleAttribute' attribute [Newfunctions]
Duplicate 'System.Reflection.AssemblyVersionAttribute' attribute [Newfunctions]

And another one in AssemblyAttributes.cs:

// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v3.1", FrameworkDisplayName = "")]

Error message:

Duplicate 'global::System.Runtime.Versioning.TargetFrameworkAttribute' attribute [Newfunctions]

I have nothing added or changed in the assembly classes. I have only installed the Azure Functions extension and PlayFab Explorer extension in Visual Studio Code. In addition, I have added the nuget packages PlayFabAllSDK and PlayFabCloudScriptPlugin to my project. I don't know what I'm doing wrong.

What is wrong with my project? How can I fix these error messages?

Error messages

Newfunctions.csproj:

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.7"/>
<PackageReference Include="PlayFabAllSDK" Version="1.81.200914"/>
<PackageReference Include="PlayFabCloudScriptPlugin" Version="1.53.190627-alpha"/>
</ItemGroup>
<ItemGroup>
<None Update="host.json">
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  <CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
2 Answers

Adding <GenerateAssemblyInfo>false</GenerateAssemblyInfo> to the project file didn't work for me. What did however work was to delete the bin and obj folders in all the projects where the error occured. Then restart Visual Studio and try to run again.

For me, the root cause was in attempting to create a new project within another project's folder (accidentally). As soon as I moved the new project to the same folder level as the first project the errors disappeared.

When we compile a project, the obj/debug/(Framework Name) folder autogenerates files. One of them is "ProjectName.AssemblyInfo.cs". This file has attributes for: Company, Configuration, Copyright, Description, FileVersion, InformationalVersion, and 4 Assembly attributes. The compiler expects the project's folder and all subfolders to only have one of these files.

Related