dotnet publish错误:该进程无法访问该文件,因为该文件正在被另一个进程使用

编程入门 行业动态 更新时间:2024-10-25 07:35:18
本文介绍了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错误:该进程无法访问该文件,因为该文件正在被另一个进程使用

本文发布于:2023-11-04 12:17:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1557917.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:该文件   进程   无法访问   错误   dotnet

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!