7

I am working in a large team with multiple branches and merges happening on a regular basis.

One thing that happens on regular basis is that web project files end up with duplicate entries for static content (.js, favicon.ico etc...).

I have two methods to removing the duplicates:

  1. Delete the item in the Project Explorer (which removes all entries as well as the on disk file), then get the file again from source control and add it back.
  2. Unload the project file, look for the duplicates, remove them (hoping they are located near one another) then reloading the project.

Both are tedious and I am not satisfied with them - do you have a better/faster/quicker method?

Oded
  • 489,969
  • 99
  • 883
  • 1,009

2 Answers2

5

The easiest way is to simply right-click on the duplicate and choose the "Exclude from Project" option. The duplicate will be disappear after refreshing the project.

gonzobrains
  • 7,856
  • 14
  • 81
  • 132
Oded
  • 489,969
  • 99
  • 883
  • 1,009
  • This solution didn't work to me. However the OP's second method ("Unload the project file, look for the duplicates,...") did work to remove the duplicates I had on my project. – Ivan Santiago Feb 26 '16 at 21:02
  • After excluding you need to include them again – Reza Jun 15 '17 at 19:47
3

For desktop apps the most annoying thing is that VS only tells you about first duplicate it encounters, and you have to rebuild over and over again after every fix. Here is a simple LINQ pad script that I use when I need to clean things up after merges:

var hash = new HashSet<string>();
using (var fs = File.OpenRead(@"path\to\csproj\file"))
using (var sr = new StreamReader(fs))
{
     while (!sr.EndOfStream)
     {
        var line = sr.ReadLine().Trim();
        if (line.StartsWith(@"<Reference") || line.StartsWith(@"<Compile") || line.StartsWith(@"<Page"))
        {
            if (!hash.Add(line))
            {
                line.Dump();
            }
        }
     }
}

It lists all the duplicates found in .csproj file (something that I wish VS did on its own by now, but oh well, maybe in another 10 years). You still have to remove duplicates manually, but having a full list greatly speeds things up.

Nikita B
  • 3,303
  • 1
  • 23
  • 41