msbuild icon indicating copy to clipboard operation
msbuild copied to clipboard

Issue a warning for duplicate items (Compile, Reference, ProjectReference)

Open KirillOsenkov opened this issue 7 years ago • 2 comments

I think MSBuild tooling should issue a warning if it encounters duplicate items such as Compile, Reference or ProjectReference. We've had bugs in Roslyn not handling duplicate items properly and I'm imagining there could be other negative repercussions from having duplicate items.

We've thought about adding the warning to the project system but it feels like they should be issues uniformly regardless of whether you're using command line build or IDE build.

There are separate bugs to harden Roslyn against duplicate items and do deduplication on all entrypoints.

KirillOsenkov avatar Jul 20 '16 23:07 KirillOsenkov

We've encountered it locally plenty of times and have written several "tattlers"/commit hooks to watch our projects to catch these. Make sure to account for relative paths as well (this is usually when it happens to us).

It'd be helpful if the tooling sorted/alphabetized these properties from within Visual Studio (we wrote tooling to do this externally and has helped our devs both in merge conflicts as well as catching these scenarios prior to their commits).

Another issue that is similar (but not identical) that we've encountered is Developers will add an Assembly Reference to a project that is ProjectReference'd (even more sinister when its been Assembly Reference and then NuGet'ed via PackageReference). Not sure MSBuild's tooling is the most appropriate place for this but its another place we've written tooling to catch these in action.

aolszowka avatar Aug 13 '19 17:08 aolszowka

For reference Nuget has already commenced work to warn about duplicate PackageReferences: https://github.com/NuGet/Home/pull/11649

Additionally, #1777 sounds like a place to host the duplicate item check.

stan-sz avatar Jul 11 '22 08:07 stan-sz

See also #3043 and #624

stan-sz avatar Jan 10 '23 10:01 stan-sz

For reference, a fix is needed to have the above work correctly.

stan-sz avatar Sep 26 '23 08:09 stan-sz