dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.02k stars 4.03k forks source link

"duplicated attribute" errors with a clean build #25044

Open alrz opened 6 years ago

alrz commented 6 years ago

A bunch of "duplicated attribute" errors with a clean build off of master, features/compiler, etc

VS: 15.6 preview 6

D:\dotnet\roslyn\Binaries\Obj\VisualBasicSyntaxGenerator\Debug\GeneratedAssemblyInfo_42.42.42.42424.vb(20,2): error BC30663: Attribute 'AssemblyInformationalVersionAttribute' cannot be applied multiple times. [D:\dotnet\roslyn\src\Tools\Source\CompilerGenerator
Tools\Source\VisualBasicSyntaxGenerator\VisualBasicSyntaxGenerator.vbproj]
D:\dotnet\roslyn\Binaries\Obj\VisualBasicErrorFactsGenerator\Debug\GeneratedAssemblyInfo_42.42.42.42424.vb(16,2): error BC30663: Attribute 'AssemblyCompanyAttribute' cannot be applied multiple times. [D:\dotnet\roslyn\src\Tools\Source\CompilerGeneratorTools\Sou
rce\VisualBasicErrorFactsGenerator\VisualBasicErrorFactsGenerator.vbproj]
D:\dotnet\roslyn\Binaries\Obj\VisualBasicErrorFactsGenerator\Debug\GeneratedAssemblyInfo_42.42.42.42424.vb(18,2): error BC30663: Attribute 'AssemblyVersionAttribute' cannot be applied multiple times. [D:\dotnet\roslyn\src\Tools\Source\CompilerGeneratorTools\Sou
rce\VisualBasicErrorFactsGenerator\VisualBasicErrorFactsGenerator.vbproj]
D:\dotnet\roslyn\Binaries\Obj\VisualBasicErrorFactsGenerator\Debug\GeneratedAssemblyInfo_42.42.42.42424.vb(19,2): error BC30663: Attribute 'AssemblyFileVersionAttribute' cannot be applied multiple times. [D:\dotnet\roslyn\src\Tools\Source\CompilerGeneratorTools
\Source\VisualBasicErrorFactsGenerator\VisualBasicErrorFactsGenerator.vbproj]
D:\dotnet\roslyn\Binaries\Obj\VisualBasicErrorFactsGenerator\Debug\GeneratedAssemblyInfo_42.42.42.42424.vb(20,2): error BC30663: Attribute 'AssemblyInformationalVersionAttribute' cannot be applied multiple times. [D:\dotnet\roslyn\src\Tools\Source\CompilerGener
atorTools\Source\VisualBasicErrorFactsGenerator\VisualBasicErrorFactsGenerator.vbproj]
D:\dotnet\roslyn\Binaries\Obj\CodeAnalysis\Debug\GeneratedAssemblyInfo_42.42.42.42424.cs(14,12): error CS0579: Duplicate 'System.Reflection.AssemblyCompanyAttribute' attribute [D:\dotnet\roslyn\src\Compilers\Core\Portable\CodeAnalysis.csproj]
D:\dotnet\roslyn\Binaries\Obj\CodeAnalysis\Debug\GeneratedAssemblyInfo_42.42.42.42424.cs(16,12): error CS0579: Duplicate 'System.Reflection.AssemblyVersionAttribute' attribute [D:\dotnet\roslyn\src\Compilers\Core\Portable\CodeAnalysis.csproj]
D:\dotnet\roslyn\Binaries\Obj\CodeAnalysis\Debug\GeneratedAssemblyInfo_42.42.42.42424.cs(17,12): error CS0579: Duplicate 'System.Reflection.AssemblyFileVersionAttribute' attribute [D:\dotnet\roslyn\src\Compilers\Core\Portable\CodeAnalysis.csproj]
D:\dotnet\roslyn\Binaries\Obj\CodeAnalysis\Debug\GeneratedAssemblyInfo_42.42.42.42424.cs(18,12): error CS0579: Duplicate 'System.Reflection.AssemblyInformationalVersionAttribute' attribute [D:\dotnet\roslyn\src\Compilers\Core\Portable\CodeAnalysis.csproj]
D:\dotnet\roslyn\Binaries\Obj\MSBuildTask\Debug\GeneratedAssemblyInfo_42.42.42.42424.cs(14,12): error CS0579: Duplicate 'System.Reflection.AssemblyCompanyAttribute' attribute [D:\dotnet\roslyn\src\Compilers\Core\MSBuildTask\MSBuildTask.csproj]
D:\dotnet\roslyn\Binaries\Obj\MSBuildTask\Debug\GeneratedAssemblyInfo_42.42.42.42424.cs(16,12): error CS0579: Duplicate 'System.Reflection.AssemblyVersionAttribute' attribute [D:\dotnet\roslyn\src\Compilers\Core\MSBuildTask\MSBuildTask.csproj]
D:\dotnet\roslyn\Binaries\Obj\MSBuildTask\Debug\GeneratedAssemblyInfo_42.42.42.42424.cs(17,12): error CS0579: Duplicate 'System.Reflection.AssemblyFileVersionAttribute' attribute [D:\dotnet\roslyn\src\Compilers\Core\MSBuildTask\MSBuildTask.csproj]
D:\dotnet\roslyn\Binaries\Obj\MSBuildTask\Debug\GeneratedAssemblyInfo_42.42.42.42424.cs(18,12): error CS0579: Duplicate 'System.Reflection.AssemblyInformationalVersionAttribute' attribute [D:\dotnet\roslyn\src\Compilers\Core\MSBuildTask\MSBuildTask.csproj]
...

Anyone else hitting this?

alrz commented 6 years ago

dotnet build also produces the following,

C:\Users\<username>\.nuget\packages\Microsoft.VSSDK.BuildTools\15.1.192\tools\VSSDK\Microsoft.VsSDK.targets(80,5): error MSB4062: The "CompareCommonBuildTaskVersion" task could not be loaded from the assembly C:\Users\<username>\.nuget\packages\Microsoft.VSSDK.BuildTools\15.1.192\tools\VSSDK\Microsoft.VisualStudio.Sdk.BuildTasks.dll. Could not load file or assembly 'System.IO.Packaging, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
...
alrz commented 6 years ago

went ahead and cleared the nuget cache. will comment if it resolves the error.

alrz commented 6 years ago

Well it didn't. so, any idea what has happened?

tannergooding commented 6 years ago

@alrz, do you have multiple GeneratedAssemblyInfo_42.42.42.42424.cs files being passed into the compilation?

alrz commented 6 years ago

I have 57 instances of GeneratedAssemblyInfo_42.42.42.42424.cs file generated (by restore.cmd) for some projects in binaries/obj/<project>/debug path with this identical content:

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.42000
//
//     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("Microsoft Corporation")]
[assembly: System.Reflection.AssemblyCopyrightAttribute("© Microsoft Corporation. All rights reserved.")]
[assembly: System.Reflection.AssemblyVersionAttribute("42.42.42.42")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("42.42.42.42424")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("2.9.0-dev-65535-01. Commit Hash: <developer build>")]

// Generated by the MSBuild WriteCodeFragment class.

not sure if all of them are passed at once to the compilation. I tried build.cmd and dotnet build Compilers.sln.

tannergooding commented 6 years ago

I have 57 instances of GeneratedAssemblyInfo_42.42.42.42424.cs file generated (by restore.cmd) for some projects in binaries/obj//debug path with this identical content:

Right, there should be one per project.

I was wondering if you had more than one being passed into any given project, which might cause an error like the above.

If you do build.cmd -binaryLog it should produce a binary log which would help in the investigation (https://github.com/Microsoft/msbuild/wiki/Binary-Log).

alrz commented 6 years ago

Yup. obj\x64\Debug\netcoreapp2.0\CSharpErrorFactsGenerator.AssemblyInfo.cs and D:\dotnet\roslyn\Binaries\Obj\CSharpErrorFactsGenerator\Debug\GeneratedAssemblyInfo_42.42.42.42424.cs are both fed into the compilation (for instance).

alrz commented 6 years ago

Those files are both autogenerated. is this a bug or something's wrong with a config somewhere? /cc @tannergooding @jaredpar

tannergooding commented 6 years ago

Yeah, I imagine the sdk assembly info isn't turned off for that project.

jasonmalinowski commented 6 years ago

@jcouv Didn't you run into this too?

jcouv commented 6 years ago

It looks familiar, but see that I hadn't filed a bug on it, so I can't confirm 100%. I think I had stopped running into it.

alrz commented 6 years ago

Had to manually delete .AssemblyInfo.cs/vb files. What did I do to deserve this.

MaStr11 commented 6 years ago

@AdamSpeight2008 experienced the same issue (he couldn't for some reason post on his own, so I'm doing so in his name). He is using VS2017 Community Release & Preview. A gist of his error list can be found here. @alrz can you provide more details on your work around as deleting didn't worked for @AdamSpeight2008.

alrz commented 6 years ago

@MaStr11 I used build.cmd -binaryLog to see what files are being fed to the compilation and from there you can find the files with possible duplicated content. Ensure that you don't run restore afterwards, cause it would regenerate those file again. Also I suggest clearing nuget cache and start over.

jcouv commented 6 years ago

Someone who is hitting this, could you clean your repo (git clean -xdf), restore then build with /bl (msbuild /v:m /m /bl Roslyn.sln), and please share the resulting binary logs? Thanks

joeryw commented 6 years ago

Anyone fixed this issue? We are having the same problem, and have no idea how to fix it. One developer in our team get's this error. The rest of the team can build this perfectly...

jaredpar commented 6 years ago

@joeryw can you ask that developer to grab a binary log of the error as @jcouv indicated above? Essentially

msbuild /v:m /m Roslyn.sln /bl

Once the build completes there will be a file named msbuild.binlog that we can look at.

alrz commented 6 years ago

Don't forget git clean -xdf bit. the time I encountered this, it seemed that my repo was getting out of date once we were moving to newer sdks.

jaredpar commented 6 years ago

@alrz yep. Unfortunately that oddness is essentially by design. Different versions of the SDK can generate different assets. Both of which will get loaded into an MSBuild evaluation but only one of which would be removed when an operation like msbuild /t:clean is executed. The only real safe way to clean and enlistment is git clean -dxf ..

lostmsu commented 3 years ago

As suggested by @alrz , the following two PowerShell commands solved the issue for me:

ls *.AssemblyInfo.cs -Recurse | Remove-Item
ls *.AssemblyInfo.vb -Recurse | Remove-Item