Custom app_offline.htm file during publish

后端 未结 9 495
遇见更好的自我
遇见更好的自我 2020-12-03 00:58

When I publish my ASP.NET MVC application it generates a app_offline.htm file to take the site offline while it updates the website and then deletes the file once the publis

相关标签:
9条回答
  • 2020-12-03 01:27

    For users of Visual Studio Express 2013 for the Web, the file is located at C:\Users[user]\AppData\Roaming\Microsoft\VWDExpress\12.0

    That one can be modified to your needs.

    0 讨论(0)
  • 2020-12-03 01:29

    I know this is old but since I found a solution after looking here I thought I should provide an answer. VS 11 holds the publishing app_offline.htm file in this location:

    C:\Users\[user]\AppData\Roaming\Microsoft\VisualStudio\11.0\app_offline.htm
    

    I have tested this and customized it and it does work if you change this file. The down side, of course, is that this is the file used for all web publishing.

    0 讨论(0)
  • 2020-12-03 01:31

    Back in 2006, Scott Gu said that there was no way to customize the file which VS generates on Publish.

    Comment within original article

    I'd be interested in solving this too, but I was unable to turn up anything definitive to the contrary on Google.

    0 讨论(0)
  • 2020-12-03 01:37

    I use my own

    app_offline.htm_
    

    file in the solution, which gets published. My deployment script then renames it (removing the trailing _) to make it active.

    I can then run my db scripts/do whatever then rename the file bringing the site back.

    0 讨论(0)
  • 2020-12-03 01:47

    The original contents of app_offline.htm are indeed stored in a mystery location (probably hard-coded inside of one of the binaries), however Visual Studio does write the contents to a physical file before uploading it.

    If you've published at least once, a simple search in a command prompt using dir C:\app_offline.htm /s/a/b should come up with the location where the temporary file is written. It should be something like C:\Users\username\AppData\Roaming\Microsoft\VisualStudio\16.0_5fc0d832\app_offline.htm. I'm not sure if that hexidecimal string at the end is the same for every installation or user.

    Setting that file to read-only does indeed prevent Visual Studio from overwriting its content, and modifications to that file will in fact be uploaded during publishing. However, it causes an internal error that can eventually prevent it from uploading over time.

    The app_offline.htm is written before the post-build event, so it just needs to be overwritten before Visual Studio starts uploading.

    A more resilient approach is to do the following:

    1) Create a custom app_offline.htm in your project. (Not in the root folder of your project, it will prevent you from using F5 Start Debugging.)

    2) Use the post-build event to copy the custom app_offline.htm from your project folder to Visual Studio's staging folder.

    Post-build event command line:

    copy /y "$(ProjectDir)Resources\app_offline.htm" 
    "C:\Users\%username%\AppData\Roaming\Microsoft\VisualStudio\16.0_5fc0d832\app_offline.htm"
    
    0 讨论(0)
  • 2020-12-03 01:49

    Have you seen this?

    App_Offline.htm

    It might not be (exactly) what you want but it does solve the issue I think.

    0 讨论(0)
提交回复
热议问题