Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 234
Josiah Avatar asked Mar 16 '17 14:03

Josiah


2 Answers

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.

like image 75
Pawel Avatar answered Oct 25 '22 20:10

Pawel


Based on Pawel's answer, I have a deploy folder containing my app_offline.html file and multiple deploy scripts to IIS. Here's a sample script I use to deploy:

copy .\app_offline.htm C:\hosting\my-project\app_offline.htm
dotnet publish ../MyProject.csproj -r win-x64 -f netcoreapp2.1 --self-contained -c Release -o C:\hosting\my-project
del C:\hosting\my-project\app_offline.htm
like image 36
Samuel Poirier Avatar answered Oct 25 '22 21:10

Samuel Poirier