Question

I have Visual Studio 2012 with TFS. I created a new file (call it "x.h") and before I checked it in I decided I didn't need it.

MSDN makes it sound so simple:

  1. In either Solution Explorer or Source Control Explorer, browse to the folder or file that you want to delete.
  2. Select the items that you want to delete, open their shortcut menu, and choose Delete.
  3. When you are ready, check in your changes.

So I went to Source Control Explorer, right-clicked the file, and chose Delete. It was removed from source control and my pending changes but is still on disk and in the Solution Explorer. When I right-click the file in Solution Explorer, Delete is not an option and Exclude From Project is disabled.

I might have more luck if I check it in first then delete it but that seems very unnecessary. Hopefully I'm just missing something obvious!

How do I delete this new file ("x.h") from my solution?

Was it helpful?

Solution

Yep. It was something obvious.

You can't delete files from the Solution while it is building.

I just tried again and the Delete option magically reappeared. I realized that it has stopped a build since I last tried.

In short, there are three different angles that a user can try to delete a file while a build is occurring and the behavior is different for each.

  1. Undo the file add from Pending Changes -> Nice error messages are given. enter image description here
  2. Delete the file from Source Control Explorer -> It lets you remove the file as I described in the question but leaves it on disk and in Solution Explorer (same behavior regardless of whether or not a build happening).
  3. Delete the file from Solution Explorer -> It quietly prevents you from shooting yourself in the foot and doesn't explain why.

The right way to do this is to cancel the build (or let it complete), then delete from Source Control AND from Solution Explorer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top