【发布时间】:2016-07-07 09:13:09
【问题描述】:
我们的解决方案 (A.sln) 需要一个由另一个(旧版)解决方案 (B.sln) 构建的二进制文件。我无法详细说明为什么这是必要的,这是一个漫长而毛骨悚然的故事。
约束
A 生成的应用程序在运行时只需要B 的工件,因此在构建过程中何时满足此依赖关系并不重要。由于命名冲突,我们不想在同一目录中构建两个项目,而是将B 的一些工件复制到A 的输出路径的子目录中。
我试过了
1) 通过将以下内容添加到A.sln,将依赖项B 作为构建目标添加到A
<Target Name="Build">
<MSBuild Projects="$(SolutionDir)..\B\B.sln" Properties=" Platform=Win32; Configuration=$(Configuration); " />
</Target>
由于某种原因,这会在A 的输出目录中构建B,这是不需要的。
2) 通过将以下内容添加到 A.sln 来向 A 调用 msbuild on B 添加构建后事件
<PropertyGroup>
<PostBuildEvent>
msbuild $(SolutionDir)..\B\B.sln /p:configuration=$(ConfigurationName)
xcopy /E /R /Y $(SolutionDir)..\B\$(ConfigurationName) $(SolutionDir)$(ConfigurationName)\B\
</PostBuildEvent>
</PropertyGroup>
由于某种原因,这适用于 VS 2015 命令提示符,但不适用于 Visual Studio 本身。 VS (2015) 抱怨说
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\CodeAnalysis\Microso
ft.CodeAnalysis.targets(219,5): error MSB4175: The task factory "CodeTaskFactory
" could not be loaded from the assembly "C:\Windows\Microsoft.NET\Framework64\v4
.0.30319\Microsoft.Build.Tasks.v12.0.dll". Could not load file or assembly 'file
:///C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Build.Tasks.v12.0.
dll' or one of its dependencies. The system cannot find the file specified. [C:\
Users\Chiel.tenBrinke\Projects\MyProject\B\CppSource\B.vcxproj]
那么,最好的(即最简单、最可维护、最干净)的方法是什么?
【问题讨论】:
标签: .net visual-studio msbuild solution msbuild-task