前言
就是asp.net core打包的项目,都是直接发布复制到iis中,但是更新的时候需要停止掉iis,才能更新,否则会报应用程序正在被占用的问题,不能像.netframework的web应用一样热更新,经过了解和百度,发现可以使用如下方式实现
将进程内改为进程外
打包后的web.config大体如下
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\xxxx.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
注意aspnetcore节点hostingModel属性是inprocess
(也可以这么写InProcess,不区分大小写),表示是在进程内
<aspNetCore processPath="dotnet" arguments=".\xxxx.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
如果改成进程外就可以热更新了,进程外是OutOfProcess
<aspNetCore processPath="dotnet" arguments=".\xxxx.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="OutOfProcess" />
适合.net6级以上的
web.config,主要是增加handlerSettings
节点
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!-- To customize the asp.net core module uncomment and edit the following section.
For more info see https://go.microsoft.com/fwlink/?linkid=838655 -->
<system.webServer>
<handlers>
<remove name="aspNetCore"/>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModulev2" resourceType="Unspecified"/>
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout">
<handlerSettings>
<handlerSetting name="experimentalEnableShadowCopy" value="true" />
<handlerSetting name="shadowCopyDirectory" value="../ShadowCopyDirectory/" />
<!-- Only enable handler logging if you encounter issues-->
<!--<handlerSetting name="debugFile" value=".\logs\aspnetcore-debug.log" />-->
<!--<handlerSetting name="debugLevel" value="FILE,TRACE" />-->
</handlerSettings>
</aspNetCore>
</system.webServer>
</configuration>
使用外部插件
使用ZipDeploy,nuget安装使用
MSDeploy
就是vs自带的那个远程发布工具
参考
https://learn.microsoft.com/zh-cn/aspnet/core/host-and-deploy/iis/?view=aspnetcore-7.0
https://stackoverflow.com/questions/63046109/after-the-release-of-net-core-3-1-hostingmodel-inprocess-always-appears-in-t
https://www.cnblogs.com/harpz/p/16174876.html
https://blog.51cto.com/u_13746169/5876561
https://blog.51cto.com/MyIO/5180715