c# - 在 TeamCity 构建结果中显示 `dnu publish` 异常

标签 c# teamcity asp.net-core dnu

我花了大约 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"

问题是

  1. 是否可以从 dnu publish 命令返回错误/异常以表明发布失败? 例如,我在发布时可能会遇到异常
    • 进程无法访问文件......或者
    • 路径长度不能超过260个字符...

但是 TeamCity Build Result 将显示为Success,因此我总是需要检查它是否真的完成了,没有任何异常。

  1. 是否有其他更好的方法/脚本来发布 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/

相关文章:

ajax - 是否可以在 ASP.NET Core 2.1 Razor 页面中刷新 View 组件?

c# - 防止 Windows 资源管理器干扰目录操作

rest - Teamcity API,项目中构建配置的状态

command-line - 如何从命令行定义 gradle 中的 teamcity ['build.number' ] 属性

c# - 使用 Expression Encoder 4 SDK 记录 Selenium 测试执行在构建服务器上失败

angular - Nginx-具有2个Nginx反向代理服务器的云服务器

c# - 如何创建自定义日历以在单击按钮时仅显示特定月份,而没有星期六和星期日?

c# - using 会在 null 上工作吗?

c# - Kinect 裁剪图像

docker - 在Windows 7中的Docker上运行ASP.NET Core WebApp时出错(调试)