visual-studio Visual Studio:如何使一个解决方案依赖于另一个?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1152684/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 10:47:24  来源:igfitidea点击:

Visual Studio: How to make one solution depend on another?

visual-studiovisual-studio-2008dependenciesprojects-and-solutions

提问by Robert Fraser

Is it possible to make a solution in VS depend on (i.e. include) an entire other solution? I've seen some stuff about "Solution Folders", but these don't seem to be the same thing....? Thanks! (BTW, I'm using VS 2008)

是否有可能使 VS 中的解决方案依赖(即包括)整个其他解决方案?我看过一些关于“解决方案文件夹”的内容,但这些似乎不是一回事......?谢谢!(顺便说一句,我使用的是 VS 2008)

采纳答案by Ryan Mann

This post is old, but these days you can easily reuse dependencies in other solutions by building nuget packages for all of them. VS 2015 has nuget package building built in but is currently a Release Candidate. In Visual Studio 2013 you can use the Nuget.Packaging nuget package to allow your project to build as a Nuget Package.

这篇文章很旧,但现在您可以通过为所有解决方案构建 nuget 包,轻松地在其他解决方案中重用依赖项。VS 2015 内置了 nuget 包构建,但目前是候选版本。在 Visual Studio 2013 中,您可以使用 Nuget.Packaging nuget 包来允许您的项目构建为 Nuget 包。

Then you can just publish new versions of your packages to a local network share and configure it as a Repository in Visual Studio.

然后,您可以将包的新版本发布到本地网络共享,并将其配置为 Visual Studio 中的存储库。

Then your other solution's projects can depend on that package.

然后您的其他解决方案的项目可以依赖于该包。

For example, say you have a reusable Utility DLL in a Solution Called "Core Framework" and you want to use a utility in there on a WebSite you are building in a solution called "XYZEcosystem".

例如,假设您在名为“核心框架”的解决方案中有一个可重用的实用程序 DLL,并且您想在一个名为“XYZEcosystem”的解决方案中构建的网站上使用其中的实用程序。

In the CoreFramework solution you would build a nuget package for the Utility Project that compiles to the utility dll and include the dll and it's pdb file in the package.

在 CoreFramework 解决方案中,您将为实用程序项目构建一个 nuget 包,该包编译为实用程序 dll 并在包中包含 dll 及其 pdb 文件。

Then you publish that to your network share.

然后您将其发布到您的网络共享。

So let's say your package has an ID like "XYZ.Core.Utilities" with a version of 1.0.0.0.

因此,假设您的包有一个 ID,如“XYZ.Core.Utilities”,版本为 1.0.0.0。

Now in XYZEcosystem you would use the package manager console, set the repository drop down to your repository and type "Install-Package XYZ.Core.Utilities" and it will install the latest version of XYZ.Core.Utilities.

现在在 XYZEcosystem 中,您将使用包管理器控制台,将存储库下拉设置为您的存储库并键入“Install-Package XYZ.Core.Utilities”,它将安装最新版本的 XYZ.Core.Utilities。

If you make a change to XYZ.Core.Utilities you can run Update-Package XYZ.Core.Utilities on XYZEcosystem and it will pick up the new version.

如果您对 XYZ.Core.Utilities 进行更改,您可以在 XYZEcosystem 上运行 Update-Package XYZ.Core.Utilities,它会选择新版本。

回答by Sam Harwell

Not really. You'd have to do one of the following:

并不真地。您必须执行以下操作之一:

  • Make a build script that builds the solutions in the correct order.
  • Pre-build solution A, and only reference the built binary outputs from it in solution B.
  • Make a third solution containing all of the projects from both solutions.
  • 制作一个构建脚本,以正确的顺序构建解决方案。
  • 预构建解决方案 A,并且仅在解决方案 B 中引用其构建的二进制输出。
  • 制作包含两个解决方案中所有项目的第三个解决方案。

The first two items are the most common, where I personally prefer the second.

前两项是最常见的,我个人更喜欢第二项。

回答by net_prog

Take a look here: https://docs.microsoft.com/en-us/archive/blogs/habibh/walkthrough-adding-an-existing-visual-studio-solution-to-another-solution

看看这里:https: //docs.microsoft.com/en-us/archive/blogs/habibh/walkthrough-adding-an-existing-visual-studio-solution-to-another-solution

Actually the method described adds all projects from another solution to the current solution, not quite what we want, but at least this saves time adding all of the projects manually one by one.

实际上所描述的方法将来自另一个解决方案的所有项目添加到当前解决方案中,这不是我们想要的,但至少这节省了手动一个一个添加所有项目的时间。

回答by darasd

A solution is a collection of assemblies that build to create some kind of executable or dll. Having one solution depend on another does not make sense. The output assembly (executable/dll) depends on the assemblies that it references. If your solution depends on other assemblies, then reference them. You can add projects to your solution (File>Add>Existing Project) and then you can add refences these projects from your output project.

解决方案是一组程序集,这些程序集构建以创建某种可执行文件或 dll。让一个解决方案依赖另一个解决方案是没有意义的。输出程序集(可执行文件/dll)取决于它引用的程序集。如果您的解决方案依赖于其他程序集,则引用它们。您可以将项目添加到您的解决方案(文件>添加>现有项目),然后您可以从您的输出项目中添加这些项目的引用。

回答by codeape

You cannot do that. And why would you want to?

你不能这样做。你为什么要这样做?

Simply add all the projects that you depend on (the projects in the 'other' solution) to the solution.

只需将您依赖的所有项目(“其他”解决方案中的项目)添加到解决方案中。

Then use project references (not file references) between the projects.

然后在项目之间使用项目引用(而不是文件引用)。