Auto-deployment with continuous integration of .NET CORE fails because it cannot modify the file 'xxx.exe'

653 views Asked by At

I have created a new ASP.NET Core Web Application. I'm using TFS (2015 Update 2) MS Build process to build and deploy my application to my Dev/QA server. I'm running my code with a Kesrel/IIS configuration on a window server.

My build Steps are:

  1. Command Line: dotnet Restore -- restores my nuget packages
  2. Command Line: dotnet build -c Dev -- builds my dev profile
  3. Command Line: dotnet publish --framework netcoreapp1.1 --runtime win7-x64 --output "C:_work\dev\svc" --configuration DEV --no-build
  4. Publish Build Artifacts: from that output folder in step 3 to my web server.

Problem: The major problem I have is that the new core applications all run as console applications, so there is an 'xxx.exe' file running, in addition to the w3svc.exe IIS app running. When my Publish Build Artifacts steps runs, the process fails because the 'xxx.exe' file is in use, and cannot be modified.

So far as I can tell, you have to use the "dotnet" CLI to build and publish your CORE applications, and you cannot use the VS Build steps.

I've tried pointing my "dotnet publish" command to directly to the web server, but that has the same problem. You can see in my "dotnet publish" command I'm indicating a configuration to use (DEV). However even if I have DEV setup in VS to do a webdeploy, the "dotnet publish" command ignores that and either puts the code in a default publish location, or the location I specified in the command. So that doesn't work like the old .net framework did either.

My hosting team won't give me access to run remote powershell scripts to stop the IIS apps and console application, and I don't see any other build steps that would work to build the CORE application.

I'm on TFS 2015 Update 2. We're soon going to be on Update 3, but I don't know if that will give me feature to fix this either. If anyone know, I'd love to hear it!!

If I stop IIS app pools and make sure the console app is also stopped, my Build and Deploy steps above, work perfectly, but I don't want to have to manually stop IIS app pools every time before a build.

2

There are 2 answers

2
OdeToCode On

ASP.NET Core still respects the presence of an app_offline.htm file, so if you can copy a file with that name to the app destination on your server before step 4, and remove the file after step 4, the deployment should work. The ASP.NET Core module watches for this file and shuts down the hosting process (the .exe).

I'm sure you can run msdeploy tasks from VSTS, and msdeploy has a parameter to create an app_offline.htm file for you (although there is currently a bug in the ASP.NET Core module deployed to Azure where the file has to be all lower case letters). Msdeploy does work in deploying a published Core application to IIS.

0
Cece Dong - MSFT On

Since stopping IIS app pools can solve the issue, you may try to install IIS Utilities to stop or start Application pool.