7

In Asp.Net Shadow copying enables assemblies that are used in an application domain to be updated without unloading the application domain. Since Mvc Core not support AppDomain and can not load duplicate different version of assembly. I'm looking for a way to update the assemblies at runtime without unload or stop site. My goal is to update the site with a new version if available on remote server.

3 Answers 3

2

You can find a workaround here: The site DLL seems to be intermittently locked when publishing. The trick consists of creating a subdirectory (eg. /PREVIOUS), move the 'old' files in that directory, change the web.config to point to the exe in that directory, publish the new site and change the web.config again. Of course, this should be scripted... If you have set 'Remove additional files at destination' you cannot work with a subdirectory, but you can put that directory elsewhere of course (as long as IIS has access to it).

1
  • It's more than that though. You also need to redirect the wwwroot and also the content root from within your project, in order to fully support on the fly updating. Othewrise your site, during the copying process, will be in a state were the old assemblies work with new content (js scripts, assets etc) before web.config is changed to point back to the original location Jun 12, 2020 at 7:50
2

I too would like this. The current best workaround I’m aware of - when you want to overwrite assemblies that are in use, place a file in the folder called:

app_offline.htm

...this will temporarily take the site offline allowing you to overwrite the files. Remove or rename the file when you’re done.

If you script this it would have minimal impact.

1

I have found the solution, which solves for me the problem of build errors in VS2017 due to locking of assemblies by dotnet.exe process, spawned by IIS Express. I've just added pre-build script to ASP.NET Core Web Application, touching applicationhost.config file, located in hidden .vs directory, which is used by IIS Express as config file. It looks in .csproj file like this:

  <Target Name="PreBuild" BeforeTargets="PreBuildEvent">
    <Exec Command="IF EXIST &quot;$(SolutionDir)\.vs\config\applicationhost.config&quot; (pushd $(SolutionDir)\.vs\config\ &amp; copy /b applicationhost.config +,, &amp; popd)" />
  </Target>

Once file is touched by the script, IIS express terminates the dotnet.exe process, allowing build to proceed successfully. The new dotnet.exe process is spawned on the next request to web application.

UPDATE

For VS 2019 location of applicationhost.config file was changed so pre-build script event in .csproj file should look slightly different:

  <Target Name="PreBuild" BeforeTargets="PreBuildEvent" Condition="$(Configuration) == 'Debug'">
    <Exec Command="IF EXIST &quot;$(SolutionDir)\.vs\<SolutionName>\config\applicationhost.config&quot; (pushd &quot;$(SolutionDir).vs\<SolutionName>\config\&quot; &amp; copy /b applicationhost.config +,, &amp; popd)" />
  </Target>

where <SolutionName> is solution file name without extension .sln. It is also required to remove the attribute hostingModel="InProcess" from the IIS Express configuration file $(SolutionDir)\.vs\<SolutionName>\config\applicationhost.config, which is automatically generated by VS on starting web application under IIS Express.

2
  • 1
    That's not actually a solution. How could you do that in production environment with normal IIS? Jun 12, 2020 at 7:46
  • I agree that this is not universal solution. It is intended primarily for development purposes and for me it still works fine (with minor changes for VS2019). Jun 12, 2020 at 9:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.