What are Visual Studio project references?

17,639

Solution 1

References are used to pull additional libraries into your project. For example, when you're creating a Windows project, you'll be using Windows forms, XML parsers, socket libraries, and lots of other useful stuff. Now, you could create all these from scratch, but that would be an insane undertaking. Instead, you can use libraries which have been pre-built, such as System.Windows.Forms (all the form stuff), System.Xml (XML parser stuff) and others.

Down at the low level, these are all DLL files precompiled by Microsoft and distributed along with Visual Studio. Add Reference allows you to add new ones of these to your project, for example, Managed DirectX for 3D isn't something which is commonly used, so must be manually added to a project.

I've also just noticed the C++ tag on this, so this may actually sound very patronising (as I may have gotten the scope of the question wrong), in which case, I didn't mean it. For C++, it will be used for C++/CLI, which is Microsoft's attempt to allow C++ to use the .NET framework.

Solution 2

For C/C++ in Visual Studio 2010 Express, adding a project reference (see first image, text in German, but you get the idea) adds a node as follows to the .vcxproj file:

<ItemGroup>
  <ProjectReference Include="..\Ws1Lib\Ws1Lib.vcxproj">
    <Project>{22c9de39-f327-408b-9918-187c0ee63a86}</Project>
  </ProjectReference>
</ItemGroup>

This will make the static library produced by the referenced project available to the referencing project and also add a non-removable project dependency (right-click the project and select project dependencies, see second image) to the referencing project.

(The effect of such click actions on project configuration files become apparent when you put the project configuration files under version control and then look at the diff.)

To create setup where one or more projects reference a static library project, see this MSDN guide: Walkthrough: Creating and Using a Static Library (C++)

Project Reference enter image description here

Share:
17,639

Related videos on Youtube

James Linden
Author by

James Linden

Updated on June 04, 2022

Comments

  • James Linden
    James Linden almost 2 years

    I came across the Framework and References tab of my project and noticed that I can "Add New Reference..." to my project, what is this functionality?

  • James Linden
    James Linden over 12 years
    So if I am understanding you correctly: it just links static libraries (which have already been built) to my current project during linking? How does this differ from adding the .lib for the linker input settings of the project.
  • slugonamission
    slugonamission over 12 years
    Aha, so you're linking native libraries. In which case, my post probably does seem very patronising, so sorry about that. References are basically just the .NET way of doing what you asked, and is used for C++/CLI. It has nothing to do with static libraries (and references are still used as dynamic libraries).
  • legalize
    legalize about 8 years
    See Lumi's answer; the references are used by the project system for native C++ projects.