.NET Core locking files
Solution 1:
This may also help when running your aspnetcore app in IIS.
Add the following to your csproj:
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="echo "App Offline" /a > "$(ProjectDir)app_offline.htm"" />
</Target>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="del "$(ProjectDir)app_offline.htm"" />
</Target>
Solution 2:
If it is on local and application is running on IIS, then in windows task bar before your date time, there should be a IIS Express Option. select IIS Express, select exit. Try running application again.
Solution 3:
In my case, I got the same issue due to dotnet watch run command even after stopping the watch mode.
Visual studio reported this error message :
The file is locked by: ".NET core Host (pid)"
killing the process with the pid fixed the issue.