Visual Studio:如何正确地处理项目依赖关系?

时间:2023-01-17 11:28:45

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.

我正在编写一个程序(在c++中),它需要几个VS项目,我想把它放在同一个VS解决方案中。我用的是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.

这里有一个简单的架构:我使用第三方库(a)进行我的项目,我有所有的头文件和.lib文件,这些文件是我用源代码编译的。

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

使用这个库,我正在编写自己的类和函数。这是我的项目(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).

然后我想为用户开发两个接口:命令行接口(C1)和GUI接口(C2),它们使用(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.

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

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.

我应该把B编译成某个.lib库,还是做点别的?如果我这样做,必须只链接B。lib到我的C1和C2项目,或者我也应该链接A。lib(换句话说,是A的内容。lib以某种方式包含在B中。*?)当然,我希望依赖项能够得到很好的处理,以便始终使用每个项目的最新版本。

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

有什么好办法吗?提前谢谢,周末愉快

2 个解决方案

#1


2  

The policy at the company I work for is to use project references.

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

The project references are more useful since they keep the information of what projects a given project depends on with the project. If you then have to add the project to a new solution you do not have to go back to the old solution file to find out what projects a given project depends on.

项目引用更有用,因为它们保存了给定项目与项目所依赖的项目的信息。如果您需要将项目添加到一个新的解决方案中,那么您不必返回到旧的解决方案文件中,以找出给定项目所依赖的项目。

#2


2  

Yes. Use Project References.

是的。使用项目引用。

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

以下是微软的官方回答。当页面谈到。net时,本地项目也几乎是一样的。

TL;DR version:

TL;博士版:

Advantages of Project References:

优势项目参考:

  1. They work on all development workstations where the solution and project set are loaded. This is because a project Globally Unique Identifier (GUID) is placed in the project file, which uniquely identifies the referenced project in the context of the current solution.
  2. 它们工作在装载解决方案和项目集的所有开发工作站。这是因为全局唯一标识符(GUID)被放置在项目文件中,它在当前解决方案的上下文中唯一地标识引用的项目。
  3. They enable the Visual Studio .NET build system to track project dependencies and determine the correct project build orders.
  4. 它们使Visual Studio . net构建系统能够跟踪项目依赖关系并确定正确的项目构建顺序。
  5. They avoid the potential for referenced assemblies to be missing on a particular computer.
  6. 它们避免了在特定计算机上丢失引用程序集的可能性。
  7. They automatically track project configuration changes. For example, when you build using a debug configuration, any project references refer to debug assemblies generated by the referenced projects, while they refer to release assemblies in a release configuration. This means that you can automatically switch from debug to release builds across projects without having to reset references.
  8. 它们自动跟踪项目配置更改。例如,当您使用调试配置构建时,任何项目引用都引用被引用的项目生成的调试程序集,而它们引用发布配置中的发布程序集。这意味着您可以在项目之间自动地从调试切换到发布版本,而不必重置引用。
  9. They enable Visual Studio .NET to detect and prevent circular dependencies.
  10. 它们使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.

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

#1


2  

The policy at the company I work for is to use project references.

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

The project references are more useful since they keep the information of what projects a given project depends on with the project. If you then have to add the project to a new solution you do not have to go back to the old solution file to find out what projects a given project depends on.

项目引用更有用,因为它们保存了给定项目与项目所依赖的项目的信息。如果您需要将项目添加到一个新的解决方案中,那么您不必返回到旧的解决方案文件中,以找出给定项目所依赖的项目。

#2


2  

Yes. Use Project References.

是的。使用项目引用。

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

以下是微软的官方回答。当页面谈到。net时,本地项目也几乎是一样的。

TL;DR version:

TL;博士版:

Advantages of Project References:

优势项目参考:

  1. They work on all development workstations where the solution and project set are loaded. This is because a project Globally Unique Identifier (GUID) is placed in the project file, which uniquely identifies the referenced project in the context of the current solution.
  2. 它们工作在装载解决方案和项目集的所有开发工作站。这是因为全局唯一标识符(GUID)被放置在项目文件中,它在当前解决方案的上下文中唯一地标识引用的项目。
  3. They enable the Visual Studio .NET build system to track project dependencies and determine the correct project build orders.
  4. 它们使Visual Studio . net构建系统能够跟踪项目依赖关系并确定正确的项目构建顺序。
  5. They avoid the potential for referenced assemblies to be missing on a particular computer.
  6. 它们避免了在特定计算机上丢失引用程序集的可能性。
  7. They automatically track project configuration changes. For example, when you build using a debug configuration, any project references refer to debug assemblies generated by the referenced projects, while they refer to release assemblies in a release configuration. This means that you can automatically switch from debug to release builds across projects without having to reset references.
  8. 它们自动跟踪项目配置更改。例如,当您使用调试配置构建时,任何项目引用都引用被引用的项目生成的调试程序集,而它们引用发布配置中的发布程序集。这意味着您可以在项目之间自动地从调试切换到发布版本,而不必重置引用。
  9. They enable Visual Studio .NET to detect and prevent circular dependencies.
  10. 它们使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.

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