dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.75k stars 1.07k forks source link

Generated AssemblyAttributes.cs should be subject to clean #21304

Open chris-smith-zocdoc opened 3 years ago

chris-smith-zocdoc commented 3 years ago

Describe the bug

Generated files like [TFM].AssemblyAttributes.cs (eg .NETFramework,Version=v4.7.2.AssemblyAttributes.cs) that reside in the obj folder should be removed by the clean target. Since these files are not able to be cleaned, we're seeing build failures across our organization where they they are inadvertently picked up by the default *.cs globs. Other generated files like AssemblyInfo.cs are correctly deleted by the clean target

To Reproduce

GenerateTargetFrameworkAttribute is true (default)

Exceptions (if any)

Typically manifests as Duplicate TargetFrameworkAttribute Attribute https://github.com/dotnet/sdk/issues/12297

Further technical details

msbuild /version 16.11.0.36601

We're in the process of converting our existing .net framework csproj files to the newer SDK style

KalleOlaviNiemitalo commented 3 years ago

Files in the obj folder should get excluded from the default globs by DefaultItemExcludes:

https://github.com/dotnet/sdk/blob/1e5386bdb072b0c4c522d489627739ab5157f802/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.DefaultItems.targets#L28-L29

Why does that not work in your scenario?

chris-smith-zocdoc commented 3 years ago

I'm not 100% sure of the exact reproduction steps yet, trying to gather info from my other team members, but I believe its related to the conversion process (going from <Project ToolsVersion="12.0" .. > to <Project Sdk="Microsoft.NET.Sdk"> ) and switching git branches (so newer intermediate outputs are present with the older format, or vice versa)

As a work around I've been having people remove the obj folder manually

Get-ChildItem -Path . -Name obj -Recurse | Remove-Item -Recurse