今天第一次将整个 asp.net core 站点发布到 IIS 上,以前都是发布到 Linux 服务器上。
开始使用 dotnet publish -c release 命令发布,用浏览器访问站点时出现下面的错误:
HTTP Error 502.5 - Process Failure Common causes of this issue: The application process failed to start
The application process started but then stopped
The application process started but failed to listen on the configured port Troubleshooting steps: Check the system event log for error messages
Enable logging the application process’ stdout messages
Attach a debugger to the application process and inspect
而在命令行下通过发布时生成的可执行文件运行站点正常(Web服务器用的是Kestrel)。
打开 web.config 文件一看发现 processPath 的值不对:
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
这个值应该是在发布时被替换的,怎么没替换呢?
到 project.json 中一看,发现下面的东东:
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
目测 web.config 的转换工作是 dotnet publish-iis 命令的任务之一。
于是手动运行 dotnet publish-iis 命令:
dotnet publish-iis -p "bin\release\netcoreapp1.1\win8-x64\publish" -f win8-x64
出现下面的错误提示(实际上在使用 dotnet publish 命令时已经出现这个错误提示,由于提示文字没有以不同颜色区分显示,所以当时没注意):
The specified framework 'Microsoft.NETCore.App', version '1.1.0-preview1-001100-00' was not found.
- Check application dependencies and target a framework version installed at:
C:\Program Files\dotnet\shared\Microsoft.NETCore.App
- The following versions are installed:
1.1.0
- Alternatively, install the framework version '1.1.0-preview1-001100-00'
project.json 中 Microsoft.NETCore.App 的版本都已经是 1.1.0 ,怎么还报找不到 1.1.0-preview1 的错误?
在 project.json 中巡视一番,遂怀疑下面的 NuGet 包还在依赖 Microsoft.NETCore.App 1.1.0-preview1。
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": {
"version": "1.0.0-*",
"imports": "portable-net45+win8+dnxcore50"
}
}
将之升级为最新版 1.1.0-preview4-final ,问题解决。
dotnet publish-iis 命令成功执行:
$ dotnet publish-iis -p "bin\release\netcoreapp1.1\win8-x64\publish" -f win8-x64
Configuring the following project for use with IIS: 'bin\release\netcoreapp1.1\win8-x64\publish'
Updating web.config at 'bin\release\netcoreapp1.1\win8-x64\publish\web.config'
Configuring project completed successfully
dotnet publish -c release 命令也生成了转换后的 web.config 。
<aspNetCore processPath=".\CNBlogs.XXX.WebApi.exe" arguments="" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false" />