Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Publish .Net Core to IIS - Process cannot access file

I am deploying my ASP .Net Core 2.0 app to my remote server using FTP. Remote Server is using IIS 8. When I publish my app, I get the following error.

Unable to add 'Project.dll' to the Web site.  The process cannot access the file because it is being used by another process (550).

I been able to bypass this by manually creating an app_offline.htm first on the publish directory, and then publishing my app via Visual Studio 2017.

I was wondering, is there an easier way of doing this? or is there an easy way I can script this, so that app_offline gets created automatically before publish? and then deleted after publish?

like image 797
FerX32 Avatar asked Oct 18 '22 00:10

FerX32


1 Answers

Anyone that's curious, I gave up depending on VS to publish my .NET Core project. I'm now using WinSCP and _PublishToWeb.bat script I created to accomplish the task.

I first created a file called _app.offline.htm on root directory my publish folder. Then when I need to publish, I run the script below.

This script does the following:
1. Builds the .NET Core project to a specific folder, let's call it "_dist" folder.
2. Connects to my ftp server/publish folder and renames "_app_offline.html" to "app_offline.html", so that the server goes offline.
3. Synchronizes _dist folder with publish folder.
4. When done, changes "app_offline.htm" to "_app_offline.html", so the website is restarted.

_PublishToWeb.bat

echo off
echo Publishing to ProjectName (Optional)
set ProjectRemoteFolder=RemoteFolderName
set ConnectionString=ftp://username:password@serverIp:serverPort
set WinSCP="path to WinSCP.com"
set ProjectDistPath="a folder where dotnet publish will build the project to"
set WebAppProject="path of the project. dotnet publish will run here"

rem Build project and put it in to distribution folder
cd %WebAppProject%
dotnet publish -c Release -o %ProjectDistPath%

rem Connect to FTP and synchronize folder
%WinSCP% /command "open %ConnectionString%/%ProjectRemoteFolder%/" "mv _app_offline.htm app_offline.htm" "synchronize remote %ProjectDistPath%" "mv app_offline.htm _app_offline.htm" "exit"

rem pause

I'm sure there are better solutions out there, but this has been working well for me so far.

like image 77
FerX32 Avatar answered Oct 21 '22 07:10

FerX32