I have a ASP.NET Core app. I run the application by running the command
dotnet run
I'm seeing the following error in one out of five situations when I build this ASP.NET Core app.
C:...\error CS2012: Cannot open 'C:...\bin\Debug\netcoreapp1.0\AAA.Web.dll' for writing -- 'The process cannot access the file 'C:...\bin\Debug\netcoreapp1.0\AAA.Web.dll' because it is being used by another process.'
In addition to the above issue, I also see no updates that I make in the CSHTML file. I have to stop the dotnet run
command, build the app again and then run the dotnet run
command.
How can I fix these issues?
Lock a file in C# using File. Lock() method . The lock method let you lock a file so another process cannot access the file. This works even if it has read/write access to the file.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With