dotnet publish错误:该进程无法访问该文件,因为该文件正在被另一个进程使用 [英] dotnet publish Error: The process cannot access the file because it is being used by another process

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

问题描述

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

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

该进程无法访问该文件,因为该文件正在被另一个文件使用过程.

The process cannot access the file because it is being used by another process.

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

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.

完整错误消息:

C:\ Program Files \ dotnet \ sdk \ 2.2.301 \ Sdks \ Microsoft.NET.Sdk \ targets \ Microsoft.NET.Publish.targets(169,5):警告MSB3026:无法复制"obj \ Debug\ netcoreapp2.2 \ TemplateWebApp.dll"更改为"bin \ Debug \ netcoreapp2.2 \ publish \ TemplateWebApp.dll".在1000毫秒内开始重试1.该进程无法访问文件'\ cpft-bi-web01 \ d $ \ Websites \ TemplateWebApp \ bin \ Debug \ netcoreapp2.2 \ publish \ TemplateWebApp.dll',因为该文件正在被另一个进程使用.[\ cpft-bi-web01 \ d $ \ Websites \ TemplateWebApp \ TemplateWebApp.csproj]

C:\Program Files\dotnet\sdk\2.2.301\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(169,5): warning MSB3026: Could not copy "obj\Debug\netcoreapp2.2\TemplateWebApp.dll" to "bin\Debug\netcoreapp2.2\publish\TemplateWebApp.dll". Beginning retry 1 in 1000ms. The process cannot access the file '\cpft-bi-web01\d$\Websites\TemplateWebApp\bin\Debug\netcoreapp2.2\publish\TemplateWebApp.dll' because it is being used by another process. [\cpft-bi-web01\d$\Websites\TemplateWebApp\TemplateWebApp.csproj]

我可以通过关闭浏览器并在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错误:该进程无法访问该文件,因为该文件正在被另一个进程使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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