Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does Visual Studio's "Add reference" actually do?

I'm playing around with build systems and more specifically with MSBuild and Visual Studio 2019. I'm working with C++ and I'm trying to learn what is happening deeply behind the scenes. I was examining the .sln and .vcxproj files and the relationship between them. Now, both files are xml files that describe properties for the MSBuild system. I have a very simple setup:

solution-setup

A Visual Studio solution containing:

  • CppTesting project (Content type - Application, .exe)

  • Library project (Content type - Static Library, .lib)

By right clicking the CppTesting project VS presents me with the option to "Add reference" to my Library project. In other words to link my CppTesting project with the Library project. After I added the reference I examined both the CppTesting.vcxproj and the Library.vcxproj files and I noticed that the reference is not described in either of them. I could not find it in the .sln file either.

My question is: What exactly happens when I use the "Add reference" option in VS. Where is the reference described?

I'm looking for something like "CppTesting references Library" in some xml file. I tried looking at the C/C++ section of the projects, the Linker section. Could not find where this dependency is described. The official documentation I found does not go deep enough and it doesn't provide me with answers.

https://learn.microsoft.com/en-us/cpp/build/adding-references-in-visual-cpp-projects?view=vs-2019

EDIT: SOLVED. It appears that the referenced library (Library.vcxproj) was not present in any of the XMLs, because it was empty (Or I was silly enough not to save my project changes). Anyway, I added some code to it, saved the solution and its projects and I got this (which was the expected result):

enter image description here

like image 684
Christian Rizov Avatar asked Jul 26 '26 12:07

Christian Rizov


2 Answers

Add reference is used to add references dll and your project in solution. To see the reference, right click your project and then click unload project, then again right click your project and click edit yourproject.csproj. You will find all references there.

like image 128
Mike Avatar answered Jul 28 '26 01:07

Mike


Changes to project and solution files do not happen immediately. When you make changes to a project or solution from within Visual Studio you can force the files to be updated by doing a Ctrl + Shift + S or a Save All from the file menu.

like image 29
skybaks Avatar answered Jul 28 '26 02:07

skybaks



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!