当我发布 ASP.NET MVC 应用程序时,它会生成一个 app_offline.htm 文件,以便在更新网站时使网站脱机,然后在发布成功后删除该文件。
这很酷,我真的很喜欢这个想法,但我想创建我自己的自定义 app_offline.htm 文件,发布操作可以识别该文件,并将其放在不会影响我的开发站点的地方 - 即它不位于我的开发网站的根目录始终使其离线。
编辑:从Scott Gu关于app_offline.htm的帖子的评论中, VS 2005 似乎无法自定义 app_offline.htm 文件 - 这在 VS 2008 和现在的 VS 2010 中是否有所改变?
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 publish is successful.
This is cool and I really like the idea, but I want to create my own custom app_offline.htm file that the publish action is aware of and put it somewhere where it doesn't effect my development site - i.e. it doesn't sit in the root of my development site rendering it offline all the time.
EDIT: From the comments on Scott Gu's post about app_offline.htm, it seems that customization of the app_offline.htm file wasn't possible with VS 2005 - has this changed with VS 2008 and now VS 2010?
发布评论
评论(10)
我知道这已经很旧了,但由于我在查看此处后找到了解决方案,因此我认为我应该提供答案。 VS 11 在这个位置保存发布
app_offline.htm
文件:我已经对此进行了测试并对其进行了自定义,如果您更改此文件,它确实可以工作。当然,缺点是这是用于所有网络发布的文件。
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: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.
许多人可能认为合适的简单解决方案只需将您自己的文件(也名为
“app_offline.htm”
)添加到您的解决方案中。我已经使用 Visual Studio 2015 测试了此方法,它确实有效。
然而,唯一的缺点是,在发布过程中,首先复制默认生成的
app_offline.htm
文件,然后复制看起来按字母顺序/接近字母顺序的解决方案文件命令。这意味着您的自定义
app_offline.htm
文件会快速(但不是立即)覆盖系统生成的文件。因此,(丑陋的)系统生成的app_offline.htm
副本可能会在启动发布后的 1-2 秒窗口内提供给请求,然后再使用您的自定义文件进行更新。发布过程会自动从远程服务器删除
app_offline.htm
,无论其内容或来源如何。优点是(相对于替换系统副本)您自己的副本是可移植的,自动特定于解决方案,并且可以与源代码管理一起使用。
我知道这个问题已经很老了,但我希望这可以帮助其他人解决这个问题。
An easy solution that many might find suitable involves simply adding your own file also named
"app_offline.htm"
to your solution.I have tested this method, using Visual Studio 2015, and it does indeed work.
However, the only drawback is that during the publishing process, the default generated
app_offline.htm
file is copied first, then the solution files in what appears to be in/near alphabetical order.This means that your custom
app_offline.htm
file quickly (but not instantly) overwrites the system generated file. Therefore the (ugly) system generated copy ofapp_offline.htm
might be served to requests within a 1-2 second window of initiating the publish, before being updated with your custom file.The publishing process automatically deletes the
app_offline.htm
from the remote server irrespective of its content or origin.The advantage is (over replacing the system copy) is that your own copy is portable, is automatically solution-specific, and works with source control.
I know this question is old, but I hope this helps others coping with this issue.
使用我自己的
我在解决方案中 文件,该文件已发布。然后,我的部署脚本将其重命名(删除结尾的 _)以使其处于活动状态。
然后我可以运行我的数据库脚本/执行任何操作,然后重命名文件以恢复站点。
I use my own
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.
app_offline.htm
的原始内容确实存储在一个神秘位置(可能是硬编码在其中一个二进制文件中),但是 Visual Studio 在上传之前会将内容写入物理文件。如果您至少发布过一次,则使用
dir C:\app_offline.htm /s/a/b
在命令提示符中进行简单搜索,应该会找到写入临时文件的位置。它应该类似于 C:\Users\username\AppData\Roaming\Microsoft\VisualStudio\16.0_5fc0d832\app_offline.htm。我不确定末尾的十六进制字符串对于每个安装或用户是否都相同。将该文件设置为只读确实可以防止 Visual Studio 覆盖其内容,并且对该文件的修改实际上会在发布过程中上传。但是,它会导致内部错误,随着时间的推移,最终可能会阻止其上传。
app_offline.htm
是在构建后事件之前编写的,因此只需在 Visual Studio 开始上传之前覆盖即可。更具弹性的方法是执行以下操作:
1) 在项目中创建自定义
app_offline.htm
。 (不在项目的根文件夹中,它会阻止您使用 F5 开始调试。)2) 使用 post-build 事件复制自定义
app_offline.htm
从项目文件夹复制到 Visual Studio 的暂存文件夹。构建后事件命令行:
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 likeC:\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:
安德鲁·布洛克的回答很有魅力!尽管这取决于您使用的视觉工作室。
是您应该首先登陆的目录,选择您的 VS 版本[8.0/9.0.....] 并编辑
app_ofile.htm
文件。Andrew Bullock's answer works like a charm! although it depends on which visual studio you are using.
is the directory you should first land at, choose your VS version[ 8.0/9.0.....] and edit the
app_offile.htm
file.您可以使用批处理文件,该文件以当前目录信息作为参数调用编译器...然后它复制 app_offline.htm 并复制新文件。从源所在的位置运行它。
我个人使用一个程序,该程序比批处理更复杂,并且还检查文件的哈希值以确定它们是否需要更新,制作新文件的 zip 并将其提取到远程主机,并消除我们指定用于单元测试的文件从测试到生产。我还将 SVN 集成合并到我的解决方案中,因此当您发布测试或生产时,您也可以选择提交到 SVN。该程序存储在网络驱动器上,并使用当前目录信息从本地 PC 上的批处理文件中调用。这样,如果发生任何更改,开发人员不必更新到新的部署程序或 app_offline。最后它删除了app_offline。
查看 http://msdn。 microsoft.com/en-us/library/system.web.compilation(v=vs.80).aspx 了解更多信息或 http://msdn.microsoft.com/en-us/library/ms229863(v=vs.80).aspx如果您只是快速批量生产!
此外,在您最初引用的帖子中,我也验证了您实际上可以更改它,但您也可以使用发布功能为其他人更改它。这就是为什么你得到了这样的答案。
You can use a batch file which calls the compiler with the current directory information as parameters... It then copies app_offline.htm and copies the new file over. Run it from where the source is.
I personally use a program which is just a bit more elaborate then the batch and also checks hash's of files to determine if they need updating makes a zip of new files and extracts it to the remote host and eliminates files we designate are for unit testing when going from test to production. I have also combined SVN integration into my solution so when you publish for test or production you also optionally commit to SVN. The program is stored on a network drive and is called from a batch file on the local PC with the current directory info. This way dev's dont have to update to the new deployer or the app_offline if any changes occur. Finally it removes the app_offline.
Check out http://msdn.microsoft.com/en-us/library/system.web.compilation(v=vs.80).aspx for more info or http://msdn.microsoft.com/en-us/library/ms229863(v=vs.80).aspx if you are just making a quick batch!
Additionally in the post you initially referenced and I have also verified you can actually change it but you change it for others using the publish feature as well. This is why you were given the answer you were.
对于 Visual Studio Express 2013 for Web 的用户,该文件位于 C:\Users[user]\AppData\Roaming\Microsoft\VWDExpress\12.0
可以根据您的需要修改该文件。
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.
早在 2006 年,Scott Gu 就表示无法自定义 VS 在 Publish 上生成的文件。
在原始文章中发表评论
我也有兴趣解决这个问题,但我无法在 Google 上找到任何明确的相反信息。
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.
2024 年,这在 Visual Studio 2022 中仍然不可能......
VS 的
app_offline.htm
本地副本似乎不再存在。我设法让这个工作相当简单。这里以及链接的 Github 问题 (#3425 和 #6692) 遗漏了某些部分或工具已从此改变。对我解决这个问题最大的帮助是 kirkone 的“VSTS DNX Tasks”存储库,其中包含以下脚本: PublishWebPackage.ps1
请注意,我使用的是 VS 2022、.Net Core 6 (TFM
net6.0
)、SDK < code>Microsoft.NET.Sdk.Web 并从 VS 内发布 - 构建 -> 发布到 Azure - 如果您要发布到其他系统,那么您将需要调整删除脚本。这可能适用于dotnetpublish
系统,但我还没有测试过。app_offline.htm
文件添加到项目的根目录。在项目中创建一个名为
RemovePublishedAppOffline.ps1
的文件, 密码,在 Azure 中找到您的应用程序并转到部署中心:有一个 wiki 页面记录了如何访问该系统 (Kudu),如果它将来发生变化:https://github.com/projectkudu/kudu/wiki/Accessing-the-kudu-service
第一个项目组将脱机文件复制到构建发布时的输出目录,VS 首先将其推送到 WebApp。第二项运行 powershell 脚本以在发布完成后删除脱机文件。
部署应用程序时,部署日志末尾应输出以下内容:
2024 and this is still not possible in Visual Studio 2022...
VS's local copy of
app_offline.htm
seems to no longer exist.I managed to get this to work fairly simply. A lot of the comments here and in the linked Github Issues (#3425 and #6692) miss out on some parts or the tools have changed since. The biggest help to me figuring this out was kirkone's "VSTS DNX Tasks" repo with this script: PublishWebPackage.ps1
Note that I'm using VS 2022, .Net Core 6 (TFM
net6.0
), SDKMicrosoft.NET.Sdk.Web
and publishing from within VS - Build->Publish to Azure - if you're publishing to some other system then you will need to adapt the remove script. This will probably work with thedotnet publish
system but I haven't tested.app_offline.htm
file to your project's root.RemovePublishedAppOffline.ps1
in your project with the following contents to remove the offline file after publish is complete, replacing placeholder text with correct values:To get the deployment username & password, find your app in Azure and go to Deployment Center:
For the vfsApiUri, go to Advanced Tools:
Then copy the link labeled
Files
:There is a wiki page documenting how to get to this system (Kudu) if it ever changes in future: https://github.com/projectkudu/kudu/wiki/Accessing-the-kudu-service
The first itemgroup copies the offline file to the output directory on building for release, which VS pushes to the WebApp first. The second item runs the powershell script to remove the offline file when publish is complete.
When you deploy your app, the following should be output at the end of the deploy log:
你见过这个吗?
App_Offline.htm
可能不是(完全)你想要什么,但它确实解决了我认为的问题。
Have you seen this?
App_Offline.htm
It might not be (exactly) what you want but it does solve the issue I think.