TFS 构建:替换测试的连接字符串

TFS Build: replace connection string for tests

我正在尝试使用 TFS Build 作为 CI 管道 (nUnit) 的一部分执行数据库测试,但我看不到如何修改连接字符串。它是通过额外的构建步骤、设置文件还是配置文件的变体完成的?

您需要确保 app.config 文件可以根据您在项目中配置的引用路径从构建代理机器中找到其引用文件。并且连接字符串必须在构建代理机器上运行才能访问您在连接字符串中定义的 SQL 服务器。详细方式和部分文章如下:

  • Create a PowerShell script/.exe that replace the connection string
  • Check-In the script/.exe into source control
  • Execute the PowerShell script/.exe during the build as a task in the build definition

对于 vNext 构建,请参考本教程:Edit a Connection String from a TFS vNext Build

对于 XMAL 构建,请参考此 link:How to: Run Database Unit Tests from Team Foundation Build-Modify the Test Project