如何更新自包含的asp.net核心应用程序并避免文件锁定 [英] how to update self contained asp.net core app and avoid file locks

查看:21
本文介绍了如何更新自包含的asp.net核心应用程序并避免文件锁定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows Server 2012 上的企业环境中部署并使用了一个自托管的 asp.net 核心应用程序.

I have a self hosted asp.net core app deployed and in use in an enterprise environment on Windows Server 2012.

我正在寻找一种自动更新过程的方法,我目前正在通过 bat 文件执行此操作,但不断收到无法删除文件的 Windows 文件锁定错误.我在bat文件中的流程如下:

I am looking for a way to automate the update process, I am currently doing this through a bat file but keep getting windows file lock errors where the file cannot be deleted. The process I am following in the bat file is as follows:

  1. 终止 Web 应用程序的 dotnet 核心进程

  1. kill the dotnet core process for the web app

清除目录(睡眠几秒钟后)

clear the directory (after sleep for a couple of seconds)

复制更新

重启网络应用

我在 2 中遇到错误,我尝试清除仍然有文件锁定的现有目录,即使我已经终止了进程 - 无法删除输出文件 - 访问被拒绝".

I am getting the errors in 2 where I try to clear out the existing directory which still has file locks even though I have killed the process - "Cannot delete output file - access is denied".

我的问题是如何就地升级自包含的 asp.net 核心 Web 应用程序并避免文件锁定?如果站点离线几秒钟,则不是问题.

My question is how can I upgrade the self contained asp.net core web app in place and avoid the file locks? If the site is offline for a few seconds it is not an issue.

谢谢

推荐答案

我可以想到删除目录会导致访问被拒绝错误的几个原因.

There a several reasons i can think of that deleting the directory gives access denied errors.

  1. 您的进程实际上尚未停止.我知道您可以使用 powershell 等待进程停止.(或检查进程是否已停止,否则再等待 3 秒)
  2. 另一个进程仍在此文件夹中运行.(甚至可能是命令行,或者文件夹中打开了 explorer.exe.)
  3. 您需要管理员权限才能删除此文件夹.
  4. 您正在执行的 bat 文件从此目录执行,并且本身正在锁定该目录.

尝试以下方法之一:

  • powershell 停止服务.它应该等到服务真正停止.
  • powershell Wait-Process 等待直到进程停止.你可以在 Stop-Process 之后直接调用它
  • Try one of the following:

    • powershell Stop-Service. It should wait until service is really stopped.
    • powershell Wait-Process Waits untill process is stopped. you can call this directly after Stop-Process
    • 尝试运行powershell以等待例如(在命令行中):

      Try to run powershell to wait like this for example (in commandline):

      powershell -Command "Wait-Process -Name MyProcess"` 
      

      (警告您可能会遇到 ExecutionPolicy 问题)

      (warning you might run into ExecutionPolicy problems)

      使用 msdeploy,您可以远程执行命令并部署您的应用程序.

      Use msdeploy, you can remote execute commands and deploy your application.

      您可以使用前置和后置脚本(以停止和启动应用程序)并且 msdeploy 它会自行为您同步文件夹/目录.

      You can use pre and post scripts (to stop and start the app) and msdeploy it self will sync the folder/directory for you.

      这篇关于如何更新自包含的asp.net核心应用程序并避免文件锁定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆