ASP.NET Web 应用程序 (MVC) 部署自动化和 Subversion
我们正在尝试将构建过程自动化到我们的临时服务器,但遇到了一个障碍,尽管相当小。我们使用 VS2010 中内置的发布功能,提交到 Subversion,然后第 3 方应用程序 (Beanstalk) 自动提取更新的文件并将它们通过 FTP 传输到临时服务器。
我们遇到的问题是,我们似乎只有以下选择:(
- 两害相权取其轻)如果我们选择使用“用本地副本替换匹配文件”,这非常有效,但有一个例外:此选项不删除从项目中删除的所有文件。这将导致过去的乱七八糟的文件出现垃圾和/或安全问题。
- 如果我们选择使用“发布前删除所有现有文件”,则会删除整个文件夹结构,包括 Subversion 用于更新跟踪的 .SVN 隐藏文件夹等。从准确性的角度来看,这似乎是最佳解决方案,但它真正破坏了本地SVN环境,而SVN环境是这种自动化的中间人。
我的问题:是否有一个简单的解决方法,或者我们忽略了一个完全不同的部署选项(我们不想从 VS 直接发布到服务器,因为我们想跟踪谁/什么/何时进行部署)?我遇到的唯一问题是在发布之前手动删除文件内容,同时保持文件夹结构完整,然后使用“用本地副本替换匹配文件”进行部署。不幸的是,这给“自动化”一词带来了全新的含义。
关于如何最好地实现这一目标有什么想法吗?
We are trying to automate the build process to our staging servers but have run into a snag, albeit fairly minor. We are using the Publish functionality built into VS2010, committing to Subversion, and then a 3rd party app (Beanstalk) automatically pulls the updated files and FTPs them to the Staging server.
The problem we've run into is that we only appear to have the following choices:
- (Lesser of 2 evils) If we choose to use "Replace matching files with local copies", this works great, with one exception: this option does not delete any files that were deleted from the project. This will lead to junk and/or security issues for unkempt files from the days of old.
- If we choose to use "Delete all existing files prior to publish", this deletes the entire folder structure, including the .SVN hidden folders that Subversion uses for Update tracking, etc. This seems like the best solution from an accuracy standpoint, but it really destroys the local SVN environment, which is the middle-man for this automation.
My question: Is there an easy work around for this, or a totally different deployment option we're overlooking (we do not want to publish directly to the server from VS, as we want to track who/what/when a deployment takes place)? The only thing I've come across is to delete the file contents manually prior to publishing, while leaving the folder structure intact, then deploying with "Replace matching files with local copies". Unfortunately, this brings on a whole new meaning of the word "automation".
Any ideas on how best to accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可能需要考虑使用 NAnt 或类似的工具来执行您希望自动化的任务,例如构建和发布到 Subversion。这是我的 Web 应用程序项目的大部分构建文件。对于 MVC 来说可能会有所不同。如果是这样,我相信您可以以此为起点。我绝不是 NAnt 专家,因此可能存在一些缺陷,但这绝对对我有用。
我必须向我想要发布的每个 .csproj 文件添加 PublishToFileSystem 目标。其来源可以 可以在这里找到。
Pastebin 上也提供了构建文件
You may want to consider using NAnt or something similar for tasks you wish to automate, like building and publishing to Subversion. This is most of my build file for a WebApplication Project. It might be different for MVC. If so, I'm sure you can use this as a starting point. I am by no means an NAnt expert so there may be some flaws, but this is definitely working for me.
I had to add a PublishToFileSystem target to each .csproj file I wanted to publish. The source for that can be found here.
Build file also available on Pastebin
我们也在 SVN 之外部署并遇到了同样的问题。我们的解决方案本质上是将项目分支为“重大”升级——我们添加和删除文件的情况,而不仅仅是修复小错误和进行通常可以通过 xcopy 处理的调整。 svn 布局如下:
就程序而言,它非常简单——如果有足够大的更改,请根据需要签入构建工件。
您可能想要尝试的另一件事,特别是如果您无法让生产位轻松“切换”分支,则可以使用更高级的工具(例如 powershell)来执行删除文件命令,这可以过滤掉 *.svn 文件夹。
We also deploy out of SVN and ran into the same problem. Our solution is to essentially branch the project for "significant" upgrades -- situations where we were adding and deleting files, not just fixing small bugs and making tweaks which you can usually handle by xcopy. Svn layout looks like:
Procedure-wise, it is pretty simple -- if there are big enough changes, check in build artifacts as appropriate.
Another thing you might want to try, especially if you cannot get your production bits to "switch" branches easily, would be to use something fancier such as powershell to execute the delete files command, that could filter out the *.svn folders.
我想说“幸运的是”这给自动化这个词带来了全新的含义:)您所描述的是应用程序发布自动化,有时也称为部署自动化。如果您确实想知道谁做了什么、在哪里、结果是什么等等,那么您正在寻找像 Nolio ASAP (http://www.noliosoft.com) 这样的产品。请告诉我这是否有帮助,因为从您的描述来看,这似乎是完美的匹配。
+丹尼尔
I would say "fortunately" this brings a whole new meaning to the word automation :) What you're describing is knows as Application Release Automation, also sometimes called Deployment Automation. If you really want to know who did what and where, what was the outcome, etc. then you are looking for a product like Nolio ASAP (http://www.noliosoft.com). Please let me know if this helps, since from what you're describing, it seems like a perfect match.
+Daniel
为什么要将站点发布到由 Subversion 处理的文件夹?
我的方法是直接处理 SVN 处理的文件夹中的文件。一旦我做出任何事情,它就会被豆茎拉到暂存区。这样,删除的文件始终会从存储库中删除,您不必担心这一点。一切总是同步的。
如果您觉得这将太多文件放入暂存区域,您仍然可以使用脚本和 Visual Studio 命令来发布站点。但我不确定 Beanstalk 与这个场景的集成效果如何。我知道 CC.net 和许多其他替代品都可以。
Why are you publishing the site to a folder that is handled by Subversion?
The way I would do it is work directly with the files in the SVN handled folders. As soon as I commit anything, it gets pulled by beanstalk to the staging area. This way, files deleted are always deleted from the repo and you don't have to worry about that. Everything is always in sync.
If you feel that this is putting too many files to the staging area, you can still use scripts and Visual Studio commands to publish the site. But I'm not sure how well Beanstalk integrates with this scenario. I know CC.net and many other alternatives do.