How do I delete a file from my Visual Studio managed solution?

Document ID : KB000020382
Last Modified Date : 14/02/2018
Show Technical Document Details

Description:

How can I delete a file from my Visual Studio managed solution while maintaining the previous versions of that file in the repository?

Solution:

From a purely SCM perspective, what you're describing is the "Remove Item" process, which will "logically" delete the item by creating a new version with an "D" tag. In future checkouts, that version with the "D" tag will prevent this item from being checked out with the rest of the project, while maintaining the history of the previous versions of that item.

Either of these options in Visual Studio will accomplish what you want to do:

  • Right click on the item in Solution Explorer and select "Exclude item from project"
  • Right click on the item in Solution Explorer and select "Remove item from project"

After taking one of these actions you must commit the change to the repository. The result will be a "D" tag on that item in the repository and future checkouts will not include that file.

The difference is that "Exclude" will leave the file out on the your local hard drive and "Remove" will delete it from the local hard drive. But in both cases, the previous versions of that file will remain in the SCM repository to maintain the history of the project.