9

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.

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.

With this library, I'm writing my own classes and function. That is my project (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

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.

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 :)

4

2 回答 2

3

是的。使用项目参考。

这是微软的官方回答。虽然该页面讨论的是 .NET,但对于本机项目来说也几乎相同。

TL;DR 版本:

项目参考的优势:

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

这是关于VS 2010 中的项目设置更改的另一篇不错的文章,其中还指出引用比项目依赖项更受欢迎。其实文章里还说VS2010解决方案转换器会自动检测Project依赖,并将其更改为Project引用。

于 2014-12-11T03:12:23.913 回答
2

我工作的公司的政策是使用项目参考。

项目引用更有用,因为它们保留了给定项目依赖于项目的项目信息。如果您随后必须将项目添加到新解决方案中,则不必返回旧解决方案文件来找出给定项目所依赖的项目。

于 2014-02-12T09:15:29.170 回答