问题
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?
回答1:
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.
回答2:
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
回答3:
I think this is a valid solution, but doesn't help when I want to script the build process.
Stop-Website "xxx"
Stop-WebAppPool "xxx"
Start-Sleep -Seconds 5
dotnet publish --output d:\publocation
Stop-WebAppPool "xxx"
Start-Website "xxx"
来源:https://stackoverflow.com/questions/42836465/publishing-a-dotnet-application-thats-already-running