visual-studio 如何将多个 Visual Studio 解决方案链接在一起?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/681990/
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
How to link multiple visual studio solutions together?
提问by Simon P
I have 3 solutions and solution A requires built versions of the dlls from solution B and C in order to compile. it is not possible to merge it to one solution...
我有 3 个解决方案,解决方案 A 需要从解决方案 B 和 C 构建版本的 dll 才能进行编译。不可能将它合并为一个解决方案......
So far it seems that Visual Studio doesnt support solution references and msbuild is clever enough to know that you are building one solution from another etc if I try that way. The overall goal is to try to make the multiple solutions seem almost like there is only one - just solution A.
到目前为止,Visual Studio 似乎不支持解决方案引用,并且 msbuild 足够聪明,可以知道如果我尝试这种方式,您正在从另一个等构建一个解决方案。总体目标是尝试使多个解决方案看起来几乎只有一个 - 只是解决方案 A。
I believe this is a common problem, but how do you link it up nicely?
我相信这是一个常见的问题,但你如何很好地将它联系起来?
采纳答案by Greg D
This question has popped up in different, but related, forms. There is actually an MSDN page that covers this.
这个问题以不同但相关的形式出现。实际上有一个MSDN 页面涵盖了这一点。
What you're looking for is a multi-solution approach akin to the Partitioned Single Solution Model for Larger Systems. Have one "everything" solution that builds everything and maintains your inter-component dependencies. This is what you build when you need to build solution A. You then have separate solutions that only include components B or C. Essentially, you'll still have 3 solutions, but you'll add the projects from solutions B and C into solution A.
您正在寻找的是类似于大型系统的分区单解决方案模型的多解决方案方法。拥有一个“一切”解决方案来构建一切并维护您的组件间依赖关系。这就是您在需要构建解决方案 A 时构建的内容。然后您将拥有仅包含组件 B 或 C 的单独解决方案。本质上,您仍将拥有 3 个解决方案,但您会将解决方案 B 和 C 中的项目添加到解决方案中一个。
回答by Paul Redman
I have recently discovered that in Visual Studio 2008 you can include existing projects in multiple solutions. The only downside so far seems to be that if you make a change to a shared project and have multiple solutions open that use that shared project you will be asked to "reload" the other solutions.
我最近发现在 Visual Studio 2008 中,您可以在多个解决方案中包含现有项目。到目前为止唯一的缺点似乎是,如果您对共享项目进行更改并打开多个使用该共享项目的解决方案,您将被要求“重新加载”其他解决方案。
So, just "Add Existing Project" to all the solutions that need the project. I am using TFS on my current site and there seems to be no issues with source control ether.
因此,只需将“添加现有项目”添加到需要该项目的所有解决方案中即可。我在当前站点上使用 TFS,源代码控制以太似乎没有问题。
回答by Dean
It should be project level you are looking at I believe. Build the projects contained within Solution B and C and then add references to the DLLs in the relevant projects in Solution A.
我相信它应该是您正在查看的项目级别。构建解决方案 B 和 C 中包含的项目,然后在解决方案 A 中的相关项目中添加对 DLL 的引用。
In Msbuild if you have a property group
在 Msbuild 中,如果您有一个属性组
<PropertyGroup>
<SolutionsToBuild>SolutionB</SolutionsToBuild>
<SolutionsToBuild>SolutionC</SolutionsToBuild>
<SolutionsToBuild>SolutionA</SolutionsToBuild>
</PropertyGroup>
Then execute the MSBuild Task
然后执行 MSBuild 任务
<MSBuild Projects="@(SolutionsToBuild)"/>
Hope this helps
希望这可以帮助
回答by bushed
You can try to automate the merge process to save some time: http://code.google.com/p/merge-solutions/
您可以尝试自动化合并过程以节省一些时间:http: //code.google.com/p/merge-solutions/
Although we had slightly different problem: about 15 solutions (~150 projects in total) that were using one common library. The problem was that if we tried to merge all of them into one in order to refactor / exterminate redundant code from common library. 1. merging 15 solutions involves a lot of clicking and waiting in VS 2. resulted solution was never up to date - nobody bothered updating it because of its size
尽管我们遇到了稍微不同的问题:大约 15 个解决方案(总共约 150 个项目)使用一个公共库。问题是,如果我们试图将所有这些合并为一个以重构/消除公共库中的冗余代码。1. 合并 15 个解决方案需要在 VS 中进行大量点击和等待 2. 产生的解决方案从来没有更新过 - 没有人因为它的大小而费心更新它
回答by Eido95
According to this answer, I would recommend you to create your own batch filewhich will build the relevant solutions for you.
根据这个答案,我建议您创建自己的批处理文件,它将为您构建相关的解决方案。
That's very handy to use because the build process will output the build progression (Similar to Output window in Visual Studio) to the command promote for each and every build executes.
这使用起来非常方便,因为构建过程会将构建进程(类似于 Visual Studio 中的输出窗口)输出到每个构建执行的命令提升。
Furthermore, in a case that you need to build one solution before the other, you can write your own build order, for example:
此外,如果您需要先构建一个解决方案,您可以编写自己的构建顺序,例如:
- build solution B
- build solution C
- build solution A (which internally uses "solution B" and "solution C" built files)
- 构建解决方案 B
- 构建解决方案 C
- 构建解决方案 A(内部使用“解决方案 B”和“解决方案 C”构建文件)
I've quickly written script to clarify the build order mentioned aboveand support most of modern Visual Studio versions.
我已经快速编写了脚本来阐明上面提到的构建顺序并支持大多数现代 Visual Studio 版本。
Regards.
问候。
回答by Yitzhak Weinberg
I fixed the issue by putting the script in the pre-build event command line and if project A is failed to build throw msg alert
我通过将脚本放在预构建事件命令行中来解决这个问题,如果项目 A 构建失败,则抛出 msg 警报
ECHO "build A project"
set AppMsg ="%SystemRoot%\System32\msg.exe"
set AppMsg
if not "%ProgramFiles(x86)%" == "" (
if exist "%SystemRoot%\Sysnative\*" set AppMsg="%SystemRoot%\Sysnative\msg.exe"
)
set AppMsg
taskkill /f /im "%PROGRAMFILES(X86)%\MSBuild.0\Bin\msbuild" "$(SolutionPath)" /t:Project_A_Name /p:Configuration=Debug;TargetFrameworkVersion=v4.5 /p:Platform="Any CPU" /p:BuildProjectReferences=false /p:VSToolsPath="%PROGRAMFILES(X86)%\MSBuild\Microsoft\VisualStudio\v14.0" 2>nul 1>nul
echo ERRORLEVEL %ERRORLEVEL%
if ERRORLEVEL 1 (
ECHO "failed to build test project"
%AppMsg% * "failed to build test project"
)
exit 0
回答by Brann
You could try to add command line build commands for the dll (in solution B and C) you depend on in the prebuild events of your projects (in solution A)
您可以尝试为项目的预构建事件(在解决方案 A 中)中依赖的 dll(在解决方案 B 和 C 中)添加命令行构建命令
回答by Brann
If you can't put projects B and C into the same solution as project A then there's no way to make sure you have binaries for B and C containing the latest source code when you build project A.
如果您不能将项目 B 和 C 放入与项目 A 相同的解决方案中,那么在构建项目 A 时,无法确保 B 和 C 的二进制文件包含最新的源代码。
The easiest solution I've seen is to have a common folder in the source code repository where every project copies its binaries if they need to be shared. Then all other projects can reference binaries in that folder as long as your local folders look the same as the repository.
我见过的最简单的解决方案是在源代码存储库中有一个公共文件夹,如果需要共享,每个项目都会复制其二进制文件。然后所有其他项目都可以引用该文件夹中的二进制文件,只要您的本地文件夹看起来与存储库相同。
Not a perfect solution, but it's pretty easy to work with.
不是一个完美的解决方案,但它很容易使用。
回答by Juozas Kontvainis
You can add a Makefile project to solution A which would build your solutions B and C (using msbuild for example) and make all the projects in A dependent on that Makefile project. This way you wouldn't be able to add project references to projects in B and C, but you can use dll references and they will always be built from latest sources.
您可以向解决方案 A 添加一个 Makefile 项目,这将构建您的解决方案 B 和 C(例如使用 msbuild)并使 A 中的所有项目依赖于该 Makefile 项目。这样您就无法向 B 和 C 中的项目添加项目引用,但您可以使用 dll 引用,并且它们将始终从最新源构建。

