将特定文件复制到 CI 服务器上的所有依赖项目

Copy certain file to all dependent projects on the CI server

我的数据层项目中有一个 post 构建事件,它根据所选的构建配置将不同的配置文件复制到目标文件夹,即

:: hibernate.cfg.xml is copied by default (set as "Content" file)
:: so override with the appropriate config for the build server

if $(ConfigurationName) == UnitTesting (
  copy "$(ProjectDir)hibernate.cfg.xml.unittesting" "$(TargetDir)hibernate.cfg.xml" /y
)

并将其复制到该项目的适当目标文件夹中(例如 Company.Project.Data\bin\x86\UnitTesting)。然而,当我在我们的 CI 服务器 (Bamboo) 上构建测试项目时,在所有引用数据层的测试项目中,我仍然得到 原始文件

如何强制 Visual Studio 或 MSBuild 将适当的配置文件复制到引用此项目以进行特定配置的所有目标?

(更新)

在查看 CI 服务器上的目标文件夹时,我注意到无论我做什么,服务器上的目标文件夹始终获取原始配置文件。事实证明,我自己将这些依赖项添加到 MSTest 用来复制必要文件的 LocalTestRun.testconfig 文件中。我很久以前就这样做了,忘记了;原因还在于引用数据层的测试项目根本没有复制配置文件。

所以最后,解决方案就是在 CI 服务器设置中指定一个不同的 .testconfig 文件(包含不同的依赖项)。

困难的方法:

 copy "$(ProjectDir)hibernate.cfg.xml.unittesting" "$(TargetDir)hibernate.cfg.xml" /y

 copy "$(ProjectDir)hibernate.cfg.xml.unittesting" "$(TargetDir)..\OtherProjectOne\bin$(Configuration)\hibernate.cfg.xml" /y

 copy "$(ProjectDir)hibernate.cfg.xml.unittesting" "$(TargetDir)..\OtherProjectTwo\bin$(Configuration)\hibernate.cfg.xml" /y

基本上,$(TargetDir) 的相对路径

由于我的问题专门针对单元测试目的复制正确的配置文件,所以我也可以将其添加为答案。

问题是我的 LocalTestRun.testconfig 文件中有以下元素:

<Deployment>
  <DeploymentItem filename="Project\DataLayer\hibernate.cfg.xml" />
</Deployment>

它总是将配置文件复制到所有测试项目的目标构建文件夹中。所以解决方案是创建一个不同的 .testconfig 文件并在我们的构建服务器上使用它。