Visual Studio:如何正确处理项目依赖关系? [英] Visual Studio: how to handle project dependencies right?

查看:535
本文介绍了Visual Studio:如何正确处理项目依赖关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个程序(用C ++),该程序需要多个VS项目,我想将它们放入同一个VS解决方案中.我正在使用Visual Studio 2010.

I'm writing a program (in C++), which requires several VS projects, that I would like to put in the same VS solution. I'm using Visual Studio 2010.

这里只是所需的体系结构:我在我的项目中使用的是第三方库(A),我拥有所有的头文件和.lib文件,这些文件都是用源代码编译的.

Here is simply the wanted architecture : I'm using a 3rd party library (A) for my project, I have all the headers and .lib files, that I compiled with the source code.

使用这个库,我正在编写自己的类和函数.那是我的项目(B).

With this library, I'm writing my own classes and function. That is my project (B).

然后,我想为用户开发两个界面:命令行界面(C1)和GUI界面(C2),它们使用(B)中定义的类和功能.

Then I would like to develop two interfaces for the users: A command line interface (C1) and a GUI interface (C2), that are using the classes and functions defined in (B).

A <-- B <-- C1
        <-- C2

我是Visual Studio的新手,我不知道如何正确处理这些依赖项. 我应该使用项目依赖项(在解决方案属性中)还是引用(在项目属性中)?实际上,我不确定到底是什么依赖项和引用在做.

I'm new to Visual Studio, and I don't know how to handle these dependencies properly. Shall I use project dependencies (in the solution properties) or references (in the project properties) ? In fact, I'm not sure what dependencies and references are doing exactly.

我应该将B编译为某个.lib库,还是做其他事情?如果这样做,则只需将B.lib链接到我的C1和C2项目,或者我也应该链接A.lib(换句话说,A.lib的内容是否包含在B.lib中?). 当然,我希望依赖性得到很好的处理,以便始终使用每个项目的最新版本.

Shall I compile B into some .lib library, or do something else ? If I do so, have to link only B.lib to my C1 and C2 projects, or should I also link A.lib (in other words, is the content of A.lib included somehow in B.lib ?). And of course I would want the dependencies to be handle well, in order to always work with the up-to-date version of each project.

有一个好的方法吗? 提前谢谢,周末愉快:)

Is there a good way of doing it ? Thank's in advance, and have a nice week-end :)

推荐答案

是.使用项目参考.

这是Microsoft的官方答案.虽然该页面讨论的是.NET,但对于本机项目,它也几乎相同.

Here is the official answer from Microsoft. While the page talks about .NET, its almost the same for native projects too.

TL; DR版本:

项目参考的优点:

  1. 它们在加载了解决方案和项目集的所有开发工作站上工作.这是因为在项目文件中放置了一个项目全局唯一标识符(GUID),该文件在当前解决方案的上下文中唯一地标识了引用的项目.
  2. 它们使Visual Studio .NET生成系统能够跟踪项目依赖关系并确定正确的项目生成顺序.
  3. 它们避免了在特定计算机上丢失参考程序集的可能性.
  4. 它们会自动跟踪项目配置更改.例如,当您使用调试配置进行构建时,任何项目引用都引用由引用项目生成的调试程序集,而它们引用发布配置中的发布程序集.这意味着您可以跨项目自动从调试切换到发布版本,而不必重置引用.
  5. 它们使Visual Studio .NET能够检测和防止循环依赖.

这是

Here is another nice article on Project Settings Changes in VS 2010 that also states that references are to be preferred over Project Dependencies. In fact, the article also says that the VS2010 solution converter automatically detects Project dependencies and changes them to Project references.

这篇关于Visual Studio:如何正确处理项目依赖关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆