Search code examples
visual-studio-2003

How to rename C++ source files in Visual Studio 2003?


I have several C++ projects in a few separate solutions in Visual Studio 2003.
I need to rename several of the directories and source-code files in these projects.
How do I rename directories and source files such that VS will recognise the new names?

If I change file names in the OS, VS ignores them. It still shows the old file names in the Solution Explorer, and double-clicking those produces an error message (something like "Could not complete the operation").

The Solution Explorer doesn't seem to provide any way to rename files.
I can select a file and see properties such as what file-system path it points to, but I can't change any of those properties.

I'm not using integrated source control.


Solution

  • I solved the problem in a few ways.

    • If I rename a directory containing a project used in a solution, I can either edit the SLN file directly, or open the solution in Visual Studio, then remove and re-add affected projects.

    • If I rename a source file used by a project, I can edit the VCPROJ file, as this contains the paths of all source files in that project.

    I also had to check all projects for "Additional Include Directories" and "Additional Library Directories". Some of these referenced renamed directories.
    I eventually fixed most of these using a separate text editor's "Find in Files" function to find directory references. This was faster than using the VS UI to check properties of each project.