如何在构建后自动执行重复性任务?
我运行一个 ASP.NET 网站解决方案,其中包含一些其他项目。 我知道 MSBuild 项目能够做到这一点,但这是最好的方法吗? 它们容易创建吗? nAnt、CruiseControl.NET 或任何其他解决方案更好吗?
当我构建网站时(使用Web 部署项目),我可以自动化部分构建,以便它不会将某些文件夹从项目复制到发布文件夹中吗? 例如,我的文件夹包含本地搜索索引、图像和文件夹的其他内容部分,但在部署项目时我从不需要或上传这些内容。
我也在寻找这种类型的解决方案来自动增加构建和版本号。
I run an ASP.NET website solution with a few other projects in it. I've known that MSBuild projects are capable of this, but is it the best way? Are they easy to create? Is nAnt, CruiseControl.NET or any other solution better?
When I build the site (using Web Deployment Projects), can I automate part of the build so that it does not copy certain folders from the project into the Release folder? For instance, I have folders with local search indexes, images and other content part of the folder, but I never need or upload those when deploying the project.
I'm also looking toward this type of solution to automatically increment build and version numbers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您不能编辑 Web 部署项目的 MSBuild 文件以使其执行您想要的操作吗?
Can't you edit the Web Deployment project's MSBuild file for it to do what you want?
我们使用 FinalBuilder 来自动执行一系列构建后/构建前任务。 还有一个网络界面,因此您可以通过登录网站并单击按钮来启动构建(或推送网站)。
http://www.finalbuilder.com/
We use FinalBuilder to automate a bunch of post build / pre build tasks. There's also a web interface so you can kick off builds (or push websites) by logging in to the web site and clicking a button.
http://www.finalbuilder.com/
除了 @Fredrik 关于将项目项设置为“复制到输出目录”的提示之外,您还可以在“生成”选项卡的项目属性中指定生成后操作,并包含 CMD 命令,例如 copy.exe 和 move.exe。
In addition to @Fredrik's tip about setting project items to "Copy to Output Directory", you can also specify a post-build action in the project's properties in the Build tab and include CMD commands like copy.exe and move.exe.
CruiseControl.NET 解决了一个不同的问题(持续集成)...但是,我在 NAnt 方面取得了巨大的成功,特别是您所要求的。 有一个学习曲线,但是一旦你熟练了,你就会想知道如果没有它你是如何相处的。
CruiseControl.NET solves a different problem (continuous integration) ... however, I've had great success with NAnt for specifically what you're asking. There's a learning curve, but once you get proficient you'll wonder how you ever got along w/o it.
MaseBase,您可以使用Web部署项目来构建和打包网站。 对于具有 Web 应用程序方面的项目,我们一直这样做。 将 WDP 分配给网站后,您可以将 .wdproj 文件作为纯文本 XML 文件打开。 最后是 MSBuild 目标的注释部分,表示构建过程中触发的事件序列。
您可以取消注释所需的目标(例如“AfterBuild”)并在其中插入必要的任务以执行重复的构建后活动。
MaseBase, you can use Web Deployment Projects to build and package Web Sites. We do that all the time for projects with a web application aspect. After you assign a WDP to a Web Site, you can open up the .wdproj file as plain-text XML file. At the end is a commented section of MSBuild targets that represent the sequence of events that fire during a build process.
You can uncomment the targets you want (e.g. "AfterBuild") and insert the necessary tasks there to carry out your repeated post-build activities.
您可以在单个文件上设置“构建操作/复制到输出目录”属性(选择文件并按 F4 打开属性窗口)以控制构建过程中发生的情况,但不适用于文件夹。 如果您不想手动执行此操作,则可以通过(预)构建任务自动执行此操作。
或者,您可以从项目中排除这些文件夹(右键单击并“从项目中排除”); 它们仍然会在那里(在解决方案资源管理器中“显示所有文件”),但在构建项目时不会包含它们。
You can set the Build Action/Copy to Output Directory property on individual files (select the file and hit F4 to open the properties window) to control what happens to them during build, but not for folders. This could probably be automated with a (pre) build task if you don't want to do it manually.
Alternatively, you can exclude these folders from the project (right click and 'exclude from project'); they'll still be there ("show all files" in solution explorer), but they won't be included when building the project.
下面是在 .wdproj 文件中编写此类任务脚本的 Web 部署项目示例:
这将允许您删除文件夹。
(我怀疑,如果您根本不想复制文件夹,则解决方案文件将是指定该文件夹的位置,尽管我不必使用它。)
Here's an example of a Web Deployment Project scripting this sort of task in the .wdproj file:
This would allow you to delete a folder.
(I suspect that if you wanted to not have the folder copy over at all, the solution file would be the place to specify that, though I haven't had to use that.)