Search code examples
asp.netasp.net-corepublishasp.net-core-1.0

Publishing a dotnet application that's already running


I'm attempting to create a script to simplify the process of publishing a .NET Core website. I'm running into an issue when I run dotnet publish against an already running server. The server is IIS with the dotnet bundle installed, so IIS uses its app pool to start dotnet.

Here's my batch file. I'm happy to use another script type:

cd src/app
dotnet build --no-incremental
dotnet publish --framework netcoreapp1.0 --configuration Release --output ../../dist

When I run the script I get this error:

"The process cannot access the file 'C:\inetpub\wwwroot\app\dist\app.dll' because it is being used by another process."

This makes sense, it appears I need to stop, deploy, and restart dotnet. Can I do this from the script? Or is my approach to this problem wrong?


Solution

  • The best way is to drop an app_offline.htm file to your application folder. This will make IIS stop your application and serve the contents of the app_offline.htm file to the user while you are copying the new version. Once you complete copying the new version of your application remove the app_offline.htm file and IIS will start your application. You can find more details on running ASP.NET Core applications with IIS in my post.