简体   繁体   English

Visual Studio解决方案依赖性

[英]Visual Studio Solution Dependencies

I'm working at an organization with a product suite based on several hundred Visual Studio solutions (mostly C++). 我在一个具有基于数百种Visual Studio解决方案(主要是C ++)的产品套件的组织中工作。 Some of these solutions generate libraries that are used by other solutions and there's also a common "include" folder containing headers that shared by multiple modules. 其中一些解决方案会生成供其他解决方案使用的库,还有一个公共的“ include”文件夹,其中包含由多个模块共享的标头。

The issue is that the dependencies are not explicitly stated anywhere, and the build system resolves dependencies by specifying a linear build order that makes sure the dependent modules get built at the right time. 问题在于,没有在任何地方明确声明依赖项,并且构建系统通过指定线性构建顺序来解析依赖项,以确保在正确的时间构建依赖模块。 This works well for the build system but leaves developers at a disadvantage when trying to work on components with many direct and indirect external dependencies. 这对于构建系统而言效果很好,但在尝试处理具有许多直接和间接外部依赖项的组件时,使开发人员处于不利地位。 For example, I might want to edit one of the library projects or shared headers and then build all the affected modules without necessarily knowing ahead of time which ones are affected. 例如,我可能想编辑一个库项目或共享头,然后构建所有受影响的模块,而不必事先知道哪些模块受影响。 Another use case involves building a module after doing a fresh pull from TFS and having the modules it depends on built first without having to build the entire system. 另一个用例涉及在从TFS重新拉动之后构建模块,并首先构建依赖于该模块的模块,而不必构建整个系统。

I am wondering if there is/are any tool(s) available that can automate dependency generation for building large projects. 我想知道是否有任何工具可以自动生成依赖关系以生成大型项目。 I have considered creating a few really big solutions that encapsulate the other solutions but that seems really awkward and clumsy. 我已经考虑过创建一些封装了其他解决方案的非常大的解决方案,但这看起来确实很笨拙。 Also, I don't like the idea of having developers manually specify dependencies as it can error prone, especially with such a large code base. 另外,我不喜欢让开发人员手动指定依赖项的想法,因为它容易出错,尤其是在这么大的代码库中。 I worked with scons a few years ago and really liked the way it could parse source files and automatically discover all the dependencies dependencies. 几年前,我与scons一起工作,并且非常喜欢它解析源文件并自动发现所有依赖项依赖项的方式。 Is there anything available today that can do the same thing with Visual Studio solutions? 如今是否有可用的Visual Studio解决方案可以做同样的事情?

This is not a duplicate of Visual Studio: how to handle project dependencies right? 这不是Visual Studio的副本:如何正确处理项目依赖项?

I need to emphasize the magnitude of the problem I am trying to solve. 我需要强调我要解决的问题的严重性。 This is a very large existing code base. 这是一个非常大的现有代码库。 In the main directory there are several hundred sub-folders, each one containing one of more VS solutions (not projects). 在主目录中,有数百个子文件夹,每个子文件夹包含一个或多个VS解决方案之一(而非项目)。 Each solution, in turn, contains one or more projects. 每个解决方案依次包含一个或多个项目。 As I said before, I'm not trying to establish dependencies among a few projects in a solution. 如前所述,我并不是试图在解决方案中的几个项目之间建立依赖关系。 The problem is much bigger than that. 问题远不止于此。 I'm trying to find a way to establish dependencies among the solutions themselves (several hundred of them). 我正在尝试找到一种在解决方案本身(数百个解决方案)之间建立依赖关系的方法。 For example, one solution may contain some projects that generate libraries for security, others for communications, etc. There may be, for example, dozens of solutions that use the communications libraries. 例如,一个解决方案可能包含一些项目,这些项目生成用于安全的库,而其他项目则用于通信,等等。例如,可能有数十种使用通信库的解决方案。 So essentially I'm trying to create a directed a cyclic graph with hundreds of nodes and potentially tens of thousands of edges. 因此,从本质上讲,我正在尝试创建一个有数百个节点和可能数以万计的边的有向循环图。

You could use cmake ( https://cmake.org/ ). 您可以使用cmake( https://cmake.org/ )。 With it, you can specify several libraries and apps to be built. 使用它,您可以指定要构建的几个库和应用程序。 Once configured, you can modify a project and the build will just update the dependent projects. 配置完成后,您可以修改项目,而构建将仅更新相关项目。 Cmake also provides a visual studio generator, so that you can continue using that IDE. Cmake还提供了Visual Studio生成器,因此您可以继续使用该IDE。

A possible disavantage to you is that, to configure, you must explictly specify, for each project (library or executable), with what projects it must be linked and what folders it must include. 对您来说,可能的不妥之处是,要进行配置,必须为每个项目(库或可执行文件)明确指定必须链接的项目以及必须包含的文件夹。 There are ways to define some global includes and links, but the use will depends on your problem. 有几种方法可以定义一些全局包含和链接,但是使用方法取决于您的问题。

VS does track dependencies (by parsing source files). VS确实可以跟踪依赖关系(通过解析源文件)。 It doesn't make sense that something could automatically set dependencies of your VS projects, in any other build tools you'd still have to specify in some way that for linking project A.exe you need to use B.lib . 在某些其他构建工具中,您仍然必须以某种方式指定要链接VS项目的依赖关系,而要链接项目A.exe ,则需要使用B.lib

If you use newer VS versions you should simply add references to lib to your exe/dll projects. 如果使用较新的VS版本,则只需将对lib的引用添加到exe / dll项目中。 If you manually added project dependencies, most likely you should remove them all, especially make sure you don't make static lib projects dependent on each other. 如果您手动添加了项目依赖项,则很可能应该将其全部删除,尤其要确保不要使静态lib项目彼此依赖。 VS allows you to do that (for example, if build of one library generates some source files that another static lib uses), but in general these shouldn't have any dependencies and this allows VS to optimize builds by building them in parallel. VS允许您执行此操作(例如,如果一个库的构建生成了另一个静态库使用的某些源文件),但是通常它们不应该具有任何依赖关系,这使VS可以通过并行构建来优化构建。

For example, commonly you could have some kind of Base.lib, then System.lib and Graphics.lib. 例如,通常您可能拥有某种Base.lib,然后是System.lib和Graphics.lib。 All of these are user by your App.exe. 所有这些都是App.exe的用户。 System.lib uses code from Base.lib, Graphics.lib uses code from System.lib and Base.lib. System.lib使用Base.lib中的代码,Graphics.lib使用System.lib和Base.lib中的代码。 So, naturally the dependency chain is clear and you go and set them in VS, and that's a mistake! 因此,自然地,依赖关系链很清晰,您可以在VS中进行设置,这是一个错误! In cases like this in VS you should make these 4 libs independent and only App.exe should be dependent on all these libs (eg it should have references to all of these). 在VS中,在这种情况下,您应该使这4个库独立,并且只有App.exe应该依赖于所有这些库(例如,它应该引用所有这些库)。 VS will figure out what is the the correct dependency of these projects. VS将找出这些项目的正确依存关系。

Regarding Cmake case: it simply generates VS projects and solutions, if you use VS then cmake cannot do more than VS itself can. 关于Cmake的情况:它仅生成VS项目和解决方案,如果您使用VS,则cmake不能做的比VS本身更多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM