Search code examples
c++visual-studiovisual-studio-2010visual-studio-2019

How to remove shortcut/alias to a .cpp and .h file from another project in Visual Studio 2019?


I've inherited a Visual Studio solution that is structured like so (code is proprietary so I can't post original):

Solution1
|_Project1 (WindowsApp)
  |_"Header Files"
    |_Utility.h
  |_"Source Files"
    |_Utility.cpp
    |_Main.cpp
...
|_Project10 (SystemService)
  |_"Header Files"
    |_Utility.h
  |_"Source Files"
    |_Utility.cpp

The Utility.h and Utility.cpp from Project1 is somehow is an alias of the Utility.h and Utility.cpp from Project10. When I say "alias" I mean:

  • If you double click to open Project1's Utility.h/.cpp while you already have the windows from Utility.h/.cpp from Project10 open, then instead of opening new windows (i.e., indicating you're looking at a copy), Visual Studio focuses on Project10's Utility.h/.cpp window.
  • If you close all Utility.h/.cpp code windows, open up Project1's Utility.h/.cpp window, make an edit and save, and open Project10's Utility.h/.cpp, you'll see those changes.

Project1 has added the project folder for Project10 to its "Additional Include Directories".

What I'd Checked

  • Project1 Utility files aren't file-shortcuts: I checked Project1's top-level project folder in Explorer.exe and did not see Utility.h/.cpp shortcut files that link back to Project10's. Only source and header files unique to Project1 were resident in Project1's folder.
  • Project1 does not reference Project10: If I right-click Project > References > Add Reference.... I don't see the checkbox for Project10 ticked.
  • Version Control didn't create these shortcuts: I checked with the version control GUI (IBM Rational ClearCase) and Project1's files aren't registered/checked-in. This tells me this has to be a Visual-Studio related feature.

Goal

The dev who structured this solution is retired and I'm the only person working on this repo. I don't know why he didn't just extract Utility.h/.cpp into a static library project. This code was written almost a decade ago, originally on VS2010, so perhaps his was an old feature or the newer features from VS2019 weren't available back then. This repo was recently updated to work on VS2019 (although there is project that depends on VS2010 v100 platform toolset).

This repo is version-controlled (IBM Rational ClearCase) and has a long history so I can't just delete the aliases, possibly breaking something. I have to figure out what the heck the dev did, undo it, and create a proper static library.


Solution

  • It looks like the original developer wanted these files to be common to both projects, so added them to Project1. If you want to keep them separate then do the following:

    • Right click on each alias file in Project1 in the Solution Explorer Window of VS. Select Remove. Do not select the Delete option as that deletes the physical file from Project10.

    If you want Project10/Utility.h and Project10/Utility.cpp linked with Project1 you should create copies of those files and put them inside Project1. It's not possible to link .o files across projects.

    While you can create shortcuts to Project10/Utility.h and Project10/Utility.cpp and put them inside Project1, this sidesteps Visual Studio's file-tracking (VS will consider them copies inside File Explorer)

    The sensible way to share .cpp files is to create a library project that you can link against.