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

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

问题描述

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

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. 您需要管理员权限才能删除该文件夹。


  1. Your process isn't actually stopped yet. I know you can use powershell to await until porcess is stopped. (or check if process is stopped yet and otherwise wait 3 more seconds)
  2. Another process still runs in this folder. (maybe even a command line, or explorer.exe is opened in the folder.)
  3. You need admin rights to delete this folder.
  4. The bat file you are executing executes from this directory, and itself is locking the directory.



尝试以下操作之一:




  • powershell停止服务
    应该等待直到服务真正停止。

  • powershell等待进程等待直到进程停止。您可以在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天全站免登陆