TeamCity 不会构建没有 app.config 的 class 库

TeamCity won't build class library with no app.config

所以我有一个正在构建的项目(一个非常简单的 class 库)。该库对依赖于特定连接字符串的外部资源进行一些调用。我已将此连接字符串放在 app.config 文件中。

但是,出于密钥安全的原因,我不希望将此 app.config 文件放在源代码管理中,因此该文件已被 'ignored'.

不幸的是,当 TeamCity 然后尝试构建库时,它抱怨它 Could not copy the file "App.config" because it was not found. 该项目确实在我的开发环境中构建和执行单元测试。

我确定我的基本想法是正确的(将字符串放入文件中,而不是将该文件放入源代码管理中),但我想我错过了一些关于如何设置的内容向上。

要使用 TeamCity 构建此库,我有哪些选择?

这是一个可行的解决方案:

在团队城市中创建一个新的 powershell 构建步骤 将以下 powershell 代码复制到构建步骤中,并将新的构建步骤设置为在 MSBuild 步骤之前执行。

## first, set the directory to the place where the file lives
Set-Location %teamcity.build.checkoutDir%\RecordingProvider\RecordingProvider

## copy the existing template file into a real app.config file
Copy-Item App.template.config -destination App.config

If (Test-Path App.config){
  ##File exists
  Write-Output "App.config exists"
  exit 0
}Else{
  ## File does not exist
  Write-Error "App.config does not exist!!"
  exit -1
} 

就这样,TeamCity 现在编译构建。

我希望还有一些其他的解决方案,但在我看到它们之前,这会让我很费力。