aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

IIS -> Lock .NET Core application DLL file

Open radenkozec opened this issue 10 years ago • 182 comments

When I try to overwrite .NET Core application DLL file using FTP on production IIS server file is locked and it cannot be overwritten.

To deploy new version I need to stop application in IIS to release lock, then overwrite. It is not possible to deploy without stopping application.

radenkozec avatar Jul 07 '16 12:07 radenkozec

See app_offline.htm: https://docs.asp.net/en/latest/hosting/aspnet-core-module.html#asp-net-core-module-app-offline-htm

Tratcher avatar Jul 07 '16 16:07 Tratcher

If you end up desiring a PowerShell way of doing it, you can use the IIS Admin cmdlets: https://technet.microsoft.com/en-us/library/ee790599.aspx

Stop-WebAppPool -Name $appPoolName

... deploy ...

Start-WebAppPool -Name $appPoolName

guardrex avatar Jul 07 '16 21:07 guardrex

Thanks for explanation @Tratcher . I am not sure if this is on your plans but this worked for previous ASP.NET MVC I think? Do you plan to implement this feature or not?

@GuardRex I cannot do it because it is shared hosting enviroment and don't have permission to stop AppPool

radenkozec avatar Jul 11 '16 07:07 radenkozec

Can you make it to 'just work' with msdeploy.exe and Azure? If I understand correctly the web site needs to be restarted to prevent file locking. -enableRule:AppOffline works but the whole website is offline for few minutes which is not a great user experience especially given that we deploy few times per day.

See also http://stackoverflow.com/q/40276582/14131

chuchuva avatar Oct 27 '16 05:10 chuchuva

@chuchuva maybe, but all magic comes with a cost. Previous versions of ASP.NET did some complicated shadow copying to work around the file locking problems.

Tratcher avatar Oct 27 '16 16:10 Tratcher

Magic or not, It worked well. I kinda miss it now after the migration to ASP.NET core...

HarelM avatar Mar 27 '17 21:03 HarelM

Agreed with @HarelM. We've run into issues with this from our automated deployments to just end user experience. We've gone from deploying about 10 times a day with the old MVC to maybe a daily deployment at night and accepting that the people using the Core app are going to be annoyed when we take it offline. While not a show stopper, it's added friction towards Core adoption.

JaCraig avatar Apr 19 '17 12:04 JaCraig

👍

Not supporting overlapped recycling is a regression.

cyriltovena avatar Jun 23 '17 13:06 cyriltovena

Are there plans to revisit this feature and put it on the road map? It's very inconvenient/unfriendly to require everybody deploying a .Net Core website to manually implement a staging-slot strategy if they want to support zero downtime deployments.

Having this feature would make the transition to .Net Core websites much smoother for many people, and would allow for faster adoption of .Net Core websites.

deadlydog avatar Oct 11 '17 02:10 deadlydog

We would like to know as well. Putting a app_offline.htm inside the applications directory does not work.

ajeckmans avatar Oct 17 '17 15:10 ajeckmans

I've only just realised this 'feature' after moving a number of sites over to AspNetCore. I can't believe it's deemed to be acceptable to take your sites offline for a few minutes every time you want to publish!

This is bad enough for me as a leader of a small team - are those practicing continuous integration on a large scale shunning AspNetCore? There is no way they would be able to have their site going offline for minutes every hour to republish!

DaleMckeown avatar Dec 01 '17 09:12 DaleMckeown

Are you deploying use FTP or xcopying? Or are you using webdeploy?

davidfowl avatar Dec 01 '17 09:12 davidfowl

I'm publishing via webdeploy to IIS.

DaleMckeown avatar Dec 01 '17 09:12 DaleMckeown

We are currently working around this issue by just deleting the web.config first (effectively killing the application), but this is not really an acceptable solution in the long run.

@DaleMckeown ideally with a continuous integration workflow you'd have multiple servers behind a load balancer. You'd then pull one server, update it, put it back en move on to the next. Ofcourse this is not always possible (like in our case), so you'll have to live with a few minutes downtime. In our case the app is back up within 30s, so this is not really an issue.

ajeckmans avatar Dec 01 '17 10:12 ajeckmans

@DaleMckeown

I'm publishing via webdeploy to IIS.

There are a few options that can be used to make deployment using webdeploy work well (it supports renaming locked files and dropping app offline automatically). Is that the case by default @shirhatti ?

@ajeckmans

We are currently working around this issue by just deleting the web.config first (effectively killing the application), but this is not really an acceptable solution in the long run.

Does that mean you're doing xcopy deployment?

davidfowl avatar Dec 01 '17 10:12 davidfowl

There are a few options that can be used to make deployment using webdeploy work well (it supports renaming locked files and dropping app offline automatically). Is that the case by default @shirhatti ?

Thanks David - sounds better than what I am currently doing (manually stopping the site & app pool in IIS). Can you point to some resources so I can investigate the implications of these approaches?

DaleMckeown avatar Dec 01 '17 10:12 DaleMckeown

@DaleMckeown some info untilI find the source of truth https://github.com/Microsoft/vsts-tasks/issues/5259#issuecomment-346202503

davidfowl avatar Dec 01 '17 10:12 davidfowl

@davidfowl We're using webdeploy to deploy to our testserver (which btw never gives us problems), from there we copy the files to our live servers using robocopy

ajeckmans avatar Dec 01 '17 11:12 ajeckmans

@ajeckmans

We are currently working around this issue by just deleting the web.config first

When the web.config is removed from the deployment, IIS will serve sensitive files from the deployment. An attacker could simply request files continuously day and night until your 30s window opens up.

@DaleMckeown

Following @ajeckmans advice if you ever want to get into the weeds a bit with a PS approach to do that, you can script the process to drop AppPools one at a time for deployment across a web farm. For an example of how that can be done, see https://github.com/guardrex/aspnetcore-iis-ps-publish ... but just look at that as an experimental example and not a production-quality script. I haven't played with that for a while, but it should (in theory) still work.

guardrex avatar Dec 01 '17 16:12 guardrex

@guardrex you're right. We copy an app_offline.htm to the dir first, then we remive the web.config, copy over the application, put back the web.config and remove the app_offline (all with a script ofc). Unfortunately just placing the app_offline file in the websites directory does not break the lock on the dlls. We need to remove the web.config, an action we don't need to do for the older asp.net full apps (like old webforms etc)

ajeckmans avatar Dec 01 '17 21:12 ajeckmans