简体   繁体   English

如何在不停止 web 服务器的情况下在现有/正在运行的站点上更新 ASP.NET 核心应用程序?

[英]How can I update ASP.NET Core app over an existing/running site without stopping the web server?

We have an ASP.NET Core site running on our test server that we would like to auto-deploy by XCopy to our IIS web server as we do our current apps, where I already have the site running.我们有一个 ASP.NET 核心站点在我们的测试服务器上运行,我们希望通过 XCopy 自动部署到我们的 IIS web 服务器,因为我们已经运行了我们当前的应用程序, I've added a publish profile that packages the site to a "publish-local" directory within the solution.我添加了一个发布配置文件,将站点打包到解决方案中的“本地发布”目录。 Whenever I try to copy over the existing site, all DLLs are being used by another process, presumably Kestrel, so I am forced to deploy to a sibling directory and re-map IIS to look at the sibling.每当我尝试复制现有站点时,所有 DLL 都被另一个进程(可能是 Kestrel)使用,因此我被迫部署到同级目录并重新映射 IIS 以查看同级。 How does one update a running ASP.NET Core site without having to manually intervene and stop either the Kestrel or IIS web servers?如何在无需手动干预和停止 Kestrel 或 IIS web 服务器的情况下更新正在运行的 ASP.NET 核心站点?

When running with IIS you can drop a file called app_offline.htm (case sensitive) to your application folder.使用 IIS 运行时,您可以将名为app_offline.htm (区分大小写)的文件拖放到应用程序文件夹中。 IIS will stop your application and will serve the contents of the app_offline.html file. IIS 将停止您的应用程序并提供app_offline.html文件的内容。 Now you can copy your application.现在您可以复制您的应用程序。 Once finished remove the app_offline.htm and IIS will start your app.完成后删除 app_offline.htm 和 IIS 将启动您的应用程序。 This is described in the docs and also in my post on running Asp.NET Core apps with IIS.这在文档我关于使用 IIS 运行 Asp.NET Core 应用程序的帖子中进行了描述。

a little cheat we use is to rename the old files first (something like my.dll.old ), then copy over the new dlls.我们使用的一个小技巧是首先重命名旧文件(类似于my.dll.old ),然后复制新的 dll。 Then you can either force or wait for an app pool restart.然后,您可以强制或等待应用程序池重新启动。

Usually I take a backup of the existing version.通常我会备份现有版本。 Then I almost simultaneously recycle the app domain (if I'm using iis) and overwrite the entire contents of the root folder.然后我几乎同时回收应用程序域(如果我使用的是 iis)并覆盖根文件夹的全部内容。 This way the app restarts with the new version of the code.这样,应用程序将使用新版本的代码重新启动。 But it has to be super quick or else there can be issues.但它必须超级快,否则可能会出现问题。 In case if anything fails backup can be used to restore to original state.如果出现任何故障,可以使用备份恢复到原始状态。

You can switch the physical path of your IIS site/application with PowerShell:您可以使用 PowerShell 切换 IIS 站点/应用程序的物理路径:

($curPath = Get-WebFilePath -PSPath "IIS:\Sites\www.example.com\MyApp")
if ($curPath -like "*Blue*") {
    Copy-Item -Path "D:\inetpub\wwwroot\MyAppPath\Staging\*" -Destination "D:\inetpub\wwwroot\MyAppPath\Green" -Recurse -Force
    Set-ItemProperty IIS:\Sites\www.example.com\MyApp -name physicalPath -value "D:\inetpub\wwwroot\MyAppPath\Green"
} else {
    Copy-Item -Path "D:\inetpub\wwwroot\MyAppPath\Staging\*" -Destination "D:\inetpub\wwwroot\MyAppPath\Blue" -Recurse -Force
    Set-ItemProperty IIS:\Sites\www.example.com\MyApp -name physicalPath -value "D:\inetpub\wwwroot\MyAppPath\Blue"
}

Use a staging folder to which you copy your new published files.使用您将新发布的文件复制到其中的临时文件夹。 Then, the above script switches between the green and blue folder.然后,上面的脚本在绿色和蓝色文件夹之间切换。 You don't have to stop or recycle your app.您不必停止或回收您的应用程序。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在不停止站点的情况下更新ASP.Net站点dll - How to update ASP.Net site dll without stopping site 如何在不创建单独站点的情况下在 IIS 上部署 ASP.NET web? - How can I deploy an ASP.NET web on IIS without creating a separate site? 如何附加针对以net47为目标的IIS中运行的ASP.NET Core网站的调试器? - How to attach debugger for ASP.NET Core web site running in IIS targeting net47? Publish asp.net web app to IIS over existing asp.net web app - Publish asp.net web app to IIS over existing asp.net web app 如何将ASP.NET Core 5网站发布到IIS? - How to publish ASP.NET Core 5 Web Site to IIS? 如何在使用VS2010的开发服务器上测试将ASP.NET Web应用程序作为64位进程运行? - How do I test running my ASP.NET web app as a 64-bit process on a development server with VS2010? 如何更新正在运行的 asp.net core 应用程序? - How to update a running asp.net core application? 如何知道我的网站在asp.net中的默认服务器? - How to know the default server of my web site in asp.net? 如何在不停止 ASP.NET Core 中的 IIS 的情况下上传我的发布者文件? - How to upload my publisher file without stopping IIS in ASP.NET Core? 如何在 Z5267A5EC9705EB7AC2C984033E06189DZ 应用程序 asp.net 和 asp.net 内核之间共享一个简单的字符串值(配置)? - How can I share a simple string value (config) between two web applications asp.net and asp.net core in IIS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM