该进程无法访问该文件

该进程无法访问该文件

本文介绍了dotnet publish错误:该进程无法访问该文件,因为该文件正在被另一个进程使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试运行 dotnet发布时出现以下错误:

I get the following error when tring to run dotnet publish:

当您尝试发布应用程序并且一直在浏览器中查看发布的版本时,由于某种原因,它会锁定文件,这似乎发生了.

This appears to happen when you try to publish your app and you have been viewing the published version in the browser, for some reason it locks out the files.

完整错误消息:

我可以通过关闭浏览器并在IIS管理器上重新启动网站来解决此问题,但这确实不理想,有人知道原因吗?

I can resolve this by closing the browser and the restarting the website on IIS Manager but this is really not ideal, does anyone know the cause of this?

推荐答案

要解决此问题,我回收了apppool.

To solve it, i recycle the apppool.

在本地环境中,我有一个构建后事件 Project->属性->建立事件->生成后事件命令行,运行位于项目目录中的 .bat 文件.

On local environment, i have a Post Build Event Project -> Properties -> Build Events -> Post-build event command line, that runs a .bat file that sits in project directory.

这是bat文件中的代码:

This is the code from bat file:

%SYSTEMROOT%\System32\inetsrv\appcmd recycle apppool /apppool.name:"YOUR APP POOL NAME"
dotnet publish --force --no-build
pause

只需确保将您的应用程序池名称替换为您的实际池名称(并保留双引号)

Just make sure you replace YOUR APP POOL NAME with your actual pool name (and keep the double quotes)

因此,每次我构建解决方案时,它都会回收池并发布应用程序.因为我只是在构建应用程序(在发布之前),所以我指定-no-build 来发布命令.

So every time i build the solution, it recycles the pool and publishes the app. Because i just build the app (right before publishing), i specify --no-build to publish command.

这篇关于dotnet publish错误:该进程无法访问该文件,因为该文件正在被另一个进程使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 16:27