我花了大约 3 天的时间来设置 TeamCity 来构建和发布 asp.net-5 项目。最后我通过使用 dnu publish
命令来发布网站。我正在使用批处理文件通过以下命令执行此操作
// stops the apppool for 'samplesite' overvise it returns exception
// The process cannot access the file '...' because it is being used by another process
call "%windir%\system32\inetsrv\appcmd" stop apppool "samplesite"
// publish the site to the --out dir
call "C:\Users\Administrator\.dnx\runtimes\dnx-coreclr-win-x86.1.0.0-beta6\bin\dnu" publish --out "F:\Sites\samplesite" --runtime dnx-clr-win-x86.1.0.0-beta6
// copies the 'prod' config.json
copy "..\..\build\configuration\samplesite\config.json" "F:\Sites\samplesite\approot\src\samplesite\config.json" /Y
// copies the 'prod' web.config
copy "..\..\build\configuration\samplesite\web.config" "F:\Sites\samplesite\wwwroot\web.config" /Y
// starts the apppool for 'samplesite'
call "%windir%\system32\inetsrv\appcmd" start apppool "samplesite"
问题是
- 是否可以从
dnu publish
命令返回错误/异常以表明发布失败? 例如,我在发布时可能会遇到异常- 进程无法访问文件......或者
- 路径长度不能超过260个字符...
但是 TeamCity Build Result 将显示为Success
,因此我总是需要检查它是否真的完成了,没有任何异常。
- 是否有其他更好的方法/脚本来发布 asp.net-5 站点?也许我只是做错了什么。
最佳答案
这有点晚了,但我有一些东西一直在为我们工作。我一直在使用 powershell 脚本来包装我的命令行调用。因为它是 PS,你可以做一个 try/catch,然后在 catch 中我使用 ##teamcity 属性来标记 team city 失败。还要确保退出时状态代码不是 0。请注意,我强制退出时状态代码为 1 以指示失败。最后,确保 PS 脚本中的任何命令行调用都以“&”开头。
因此,例如调用 DNU 发布(我正在使用我在 team city 中设置的环境变量来指示 dnx 版本)。
try
{
& dnvm use $env:dnxversion -arch x64
& dnu publish --no-source --configuration Release --runtime dnx-clr-win-x64.$env:dnxversion
}
catch
{
Write-Error $_
##teamcity[buildStatus status='FAILURE']
[System.Environment]::Exit(1)
}
关于c# - 在 TeamCity 构建结果中显示 `dnu publish` 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32338218/