Running an ASP.Net Core application will usually lock some .exe and/or .dll files.
This makes it impossible to publish a new version of the application without stopping it first.
For this reason .Net Core team has introduced a Shadow copy feature. It is available starting from the version of .Net 6.0
When enabled the system will automatically copy the folder containing the application to the specified place and run it from there.
It will then monitor the original folder for changes and if new or modified files appear it will make another copy and restart the app.
It makes it very similar to the Classic ASP.Net where it was a default behaviour.
However it differs in that you will need to enable it and also specify a folder for the shadow copies.
In our hosting environment for each website we create two folders. One starts with www... This is where you place your website content. Another one starts with Protected...
You can use this folder for any files which should not be accessible from the Web.
The protected folder is an ideal place where to put your shadow copies.
You can Enable the shadow copies in the Web.Config files of your Application.
Place the handlerSettings section inside your aspNetCore tag similar to this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<aspNetCore processPath="Executable.exe" stdoutLogEnabled="false" hostingModel="InProcess">
<handlerSettings>
<handlerSetting name="enableShadowCopy" value="true" />
<handlerSetting name="shadowCopyDirectory" value="../Protected.../ShadowCopy" />
<handlerSetting name="cleanShadowCopyDirectory" value="true" />
</handlerSettings>
</aspNetCore>
</system.webServer>
</location>
</configuration>
Replace Protected... in the shadowCopyDirectory with the name of your protected folder.