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:
Project1
has added the project folder for Project10
to its "Additional Include Directories".
Project
> References
> Add Reference...
. I don't see the checkbox for Project10
ticked.Project1
's files aren't registered/checked-in. This tells me this has to be a Visual-Studio related feature.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.
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:
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.