'Visual Studio 2022: C++ project's output DLL not available to sibling C# project's output assembly
In Visual Studio 2022, I have a solution containing a C# project "Application" that builds into a class library (DLL) targeting .NET 6.0. The Application project depends on a C++ DLL project "Legacy" also in the solution. However, when I build the solution, the Legacy DLL does not get copied into Application's output folder, and so when the overall program is run, it crashes when it realises it cannot find Legacy.dll. I want Visual Studio to place the Legacy .dll in the same folder as the Application assembly during the solution build.
I added the Legacy project to the dependency list of the Application project, but it shows up in the dependency list with a little yellow warning triangle, and I cannot figure out what its problem is. This is probably a clue, if only I could understand it!
If I manually copy Legacy.dll into the same folder as Application.dll, it all runs fine.
There is a third project, another C# project, also added as a dependency of the Application project (without a warning triangle), and its output assembly does get copied over during the solution build, and recognised at runtime. It seems odd to me that while Visual Studio automatically handles the copying over of a sibling C# output assembly, it does not do the same for a sibling C++ output library. Have I overlooked some configuration setting?
If I had to solve this by configuring a project "output" setting or post-build event, it seems it would be quite tricky: currently, the Application assembly is output to the relative folder "Application\bin\Debug\net6.0-windows", whereas the Legacy library is output to the relative folder "x64\Debug". Both paths are relative to the VS Solution file location, using default project settings apart from the Legacy project platform being configured to x64. It seems I would have to compose some complex path from solution variables pertaining to the Application project, within the Legacy project's settings, taking into account the solution configuration and platform. Is that even possible? The Legacy project's output is configured as "$(OutDir)$(TargetName)$(TargetExt)", but the Application project's output is listed as "bin" and does not appear to contain any variables, making it difficult to figure out what to do to mimic its output folder in the C++ project settings.
I'm hoping someone has done this before and found there is a trivial solution!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
