【发布时间】:2014-09-23 00:01:58
【问题描述】:
假设最新版本的 MSBuild,假设我有 3 个项目 ProjA、ProjB 和 ProjC。我在 A 和 B 中有一个自定义目标,将各个输出(bin 项)复制到自定义路径 $(CustomOutputPath) - 这一切都可以单独工作。 ProjC 也有一个自定义目标,但除了将其文件复制到 $(CustomOutputPath) 之外,它还首先清理输出路径,然后链接 ProjA 和 ProjB,以便基本上所有 3 个项目的文件都在自定义输出路径中。
假设我无法更改此要求。
我的 ProjC 目标如下所示:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Contains groups and properties only like
CustomOutputPath and BuildProjects -->
<Import Project="SharedGroups.msbuild"/>
<Target Name="AfterBuild">
<!-- Removing old output -->
<RemoveDir Directories="$(CustomOutputPath)" />
<ItemGroup>
<!-- Arbitrary contents of this project -->
<FilesToCopy Include="**\*.*" />
</ItemGroup>
<!-- this works fine -->
<Copy SourceFiles="@(FilesToCopy)"
DestinationFolder="$(CustomOutputPath)"
OverwriteReadOnlyFiles="true" />
<!-- Once cleanup and copy is completed, I want to run all the other
projects builds which contain similar but specific copy tasks as
above, with no clean up. BuildProjects is an ItemGroup of all
the projects I want to build -->
<MSBuild Projects="@(BuildProjects)"
Properties="Configuration=$(Configuration); BuildProjectReferences=true"/>
</Target>
</Project>
我遇到的问题是我在最后一步中尝试构建的项目之一失败了,因为它引用了解决方案中的另一个项目,该项目不是作为BuildProjectReferences=true 指令的一部分构建的,所以它找不到DLL。如果我单独构建此依赖项,则 MSBuild 任务将起作用,但我不想独立构建此项目。
为什么我引用的项目没有被构建,有没有更好的方法来使用 MSBuild?
注意:我对其他解决方案持开放态度 - 我尝试对 ProjC 进行 ProjA 和 ProjB 引用(因此不需要 ProjC 目标底部的 MSBuild 任务),但是 C 中的清理步骤发生在 A 和 B 复制之后他们的输出,所以这不起作用。
【问题讨论】:
标签: msbuild