I got following error while running dotnet build
command on my .NET Core project.
C:\\Program Files\\dotnet\\sdk\\2.1.2\\Microsoft.Common.Curre
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.
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.
command you need to run
netstat -ano -p TCP | find /I "listening" | find /I "{your port number}"
taskkill /F /PID {your process ID}
How to manually stop kestrel server
Some references for this issue are:
How to manually stop kestrel server. Question asked on SO
Port localhost:5000 not released causing error System.IO.IOException: Failed to bind to address http://127.0.0.1:5000: address already in use. issue posted on github
terminating dotnet run doesn't terminate child. Issue on github
Windows: How to kill process by port. Blog post
A simple solution in VisualStudio Code is simply to kill the terminal.
Afterwards restart the PowerShell or CMD terminal either by starting a new terminal in the Terminal tab (Terminal - New Terminal) or by using the shortcut Ctrl + Shift + `