What are Visual Studio project references?

2019-04-04 22:52发布

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?

2条回答
乱世女痞
2楼-- · 2019-04-04 23:41

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.

查看更多
3楼-- · 2019-04-04 23:41

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

查看更多
登录 后发表回答