错误:该进程无法访问文件,因为在.NET Core上通过CLI构建项目时,该文件正被另一个进程使用 [英] Error the process cannot access the file because it is being used by another process while building project by CLI on .NET Core
问题描述
在.NET Core项目上运行 dotnet build
命令时遇到以下错误。
I got following error while running dotnet build
command on my .NET Core project.
C:\Program Files\dotnet\sdk\2.1.2\Microsoft.Common.CurrentVersion.targets(4106,5
): warning MSB3026: Could not copy "obj\Debug\netcoreapp2.0\Blog-Yantra.dll" to
"bin\Debug\netcoreapp2.0\Blog-Yantra.dll". Beginning retry 1 in 1000ms. The proc
ess cannot access the file 'E:\learn\blog\Blog-Yantra\bin\Debug\netcoreapp2.0\Bl
og-Yantra.dll' because it is being used by another process. [E:\learn\blog\Blog
-Yantra\Blog-Yantra.csproj]
我的csproj文件如下:
And my csproj file looks like:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TypeScriptToolsVersion>2.3</TypeScriptToolsVersion>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.1" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="2.0.0" />
</ItemGroup>
</Project>
推荐答案
所以,我在这里提出解决方案。 br>
有了进程运行和锁定程序集,因为我通过dotnet cli进行了 dotnet运行
来运行项目,而我做了 Ctrl + c 终止正在运行的进程。但是 Ctrl + c 并没有杀死所有进程,Childs继续运行并锁定程序集,即kestrel服务器仍在同一端口上运行。
So, here I come up with the solution.
There was process running and lock assemblies, since I did dotnet run
to run the project through dotnet cli and I did Ctrl + c to terminate the running process. But Ctrl + c didn't killed the all process and Childs continue running and lock assemblies i.e kestrel server was still running on the same port.
要杀死正在运行的kestrel服务器,我必须按照以下命令运行。
To kill the running kestrel server I had run following command.
C:\Users\Kiran>netstat -ano -p TCP | find /I "listening" | find /I "2492"
TCP 127.0.0.1:2492 0.0.0.0:0 LISTENING 820
C:\Users\Kiran>taskkill /F /PID 820
SUCCESS: The process with PID 820 has been terminated.
您需要运行的命令
netstat -ano -p TCP | find /I "listening" | find /I "{your port number}"
taskkill /F /PID {your process ID}
某些参考
未释放端口localhost:5000,从而导致错误System.IO.IOException:无法绑定到地址http://127.0.0.1:5000:地址已在使用中。在github上发布的问题
terminating dotnet run
doesn't terminate child. Issue on github
这篇关于错误:该进程无法访问文件,因为在.NET Core上通过CLI构建项目时,该文件正被另一个进程使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!