iis 即使使用-enableRule:AppOffline,从命令行进行Webdeploy也不会使应用脱机

wwwo4jvm  于 2023-08-05  发布在  其他
关注(0)|答案(2)|浏览(156)

当我尝试从命令行运行此命令来部署asp.net核心网站时:

"C:\\Program Files\\IIS\\Microsoft Web Deploy V3\\msdeploy.exe" -allowUntrusted -verb:sync -sourc
e:contentPath="%USERPROFILE%\ProjectFolder\bin\release\netcoreapp1.1\publish" -dest:contentPath="sitename",ComputerNa
me="https://siteurl.com:8172/msdeploy.axd?site=sitename",UserName='myusername',Password='mypassword',AuthType='Basic' -enableRule:AppOffline -retryAttempts:20

字符串
获取此错误:

Error Code: ERROR_FILE_IN_USE


当我停止Web服务器上的网站时,部署成功:
我期待-enableRule:AppOffline应该强制网站离线。但它仍然保持对网站dll的锁定。
如何强制webdeploy覆盖文件?

wtlkbnrh

wtlkbnrh1#

您能否在站点上看到是否正在创建App_Offline. htm?如果是,请尝试重命名为app_offline. htm(全部小写)。这会关闭网站吗?App_Offline.htm文件的AspNetCoreModule中存在区分大小写的错误,请参见here

ldfqzlk8

ldfqzlk82#

哇。这期对我来说是一只熊。我无法在实际部署命令中获取-enableRule:AppOffline。我也无法在pubxml文件中使用它:

<PropertyGroup>
    <EnableMSDeployAppOffline>true</EnableMSDeployAppOffline>
</PropertyGroup>

字符串
(我使用的是IIS v10)
这个Microsoft blog post表明这两个都可以工作,但对我来说没有骰子!
总之,这两篇文章对我帮助很大:

  1. https://github.com/aspnet/AspNetCoreModule/issues/50#issuecomment-268820798
  2. https://learn.microsoft.com/en-us/iis/publish/deploying-application-packages/taking-an-application-offline-before-publishing
    真实的的诀窍是在第二个参考,瓷砖上写着“发布之前”。因此,您需要在主部署之前单独运行msdeploy.exe
    下面是我使用的PowerShell代码:
# Deploy app_offline.htm
$IisApp = Get-IisAppName
$AppOfflineFilePath = "`"C:\path with spaces\app_offline.htm`""

Log-Begin "Deploy app_offline.htm"
& $MsDeployPath -verb:sync -source:contentPath=$AppOfflineFilePath -dest:contentPath=$IisApp/app_offline.htm,ComputerName=$ServerName,UserName=$UserName,Password=$Password,IncludeAcls="False"
Log-End "Deploy app_offline.htm" $LastExitCode

Write-Host "Sleeping for 4 seconds to give the app_offline.htm a chance to take effect."
Write-Host "If you get a locked DLL error, just try the deployment again!"
Start-Sleep -Seconds 4

# Within the ZIP file is a MS Web Deploy Package ZIP, a cmd (to run the deploy), and some other files.
$DeployCommandFilePath = Get-ChildItem $pwd *.deploy.cmd -Recurse | Where-Object {$_.FullName.length -lt 260} | Select-Object -First 1 | Resolve-Path -Relative

Log-Begin "deploy.cmd"
& $DeployCommandFilePath /Y /M:$ServerName /U:$UserName /P:$Password
Log-End "deploy.cmd" $LastExitCode


请注意,我添加了一个短暂的休眠,以使app_offline. htm文件有机会生效。这不是立即的。
我已经将IIS设置为自动删除部署中的app_offline. htm文件,所以我不需要这样做,但如果您需要,可以使用以下代码:

# Delete app_offline.htm
Log-Begin "Delete app_offline.htm"
& $MsDeployPath -verb:delete -dest:contentPath=$IisApp/app_offline.htm,ComputerName=$ServerName,UserName=$UserName,Password=$Password,IncludeAcls="False"
Log-End "Delete app_offline.htm" $LastExitCode

相关问题