What are Visual Studio project references?

那年仲夏 提交于 2019-12-05 12:05:53

问题


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?


回答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.




回答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++)



来源:https://stackoverflow.com/questions/8115974/what-are-visual-studio-project-references

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!