脚本缩小和与MSBuild的持续集成 [英] Script Minification and Continuous Integration with MSBuild

查看:185
本文介绍了脚本缩小和与MSBuild的持续集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个最近的项目,我一直在C#/ ASP.NET工作我有一些相当复杂的JavaScript文件和一些漂亮的样式表。随着这些脚本资源的大小增加,建议缩小资源,并保留您的网页尽可能轻,当然。我知道许多开发人员在调试之后将JavaScript资源手动输入到压缩器中,然后部署应用程序。

On a recent project I have been working on in C#/ASP.NET I have some fairly complicated JavaScript files and some nifty Style Sheets. As these script resources grow in size it is advisable to minify the resources and keep your web pages as light as possible, of course. I know many developers who hand-feed their JavaScript resources into compressors after debugging and then deploy their applications.

当涉及到源代码控制和自动化构建在令人满意的世界持续集成(感谢 CruiseControl.NET );手压缩根本不会做。维护源代码控制和提供压缩资源的唯一方法是保持JS / CSS源&他们的被缩小的弟兄在一个单独的目录结构。然后只注册一组资源,或者在代码隐藏中注册其他资源。然而,如果开发人员更改JS / CSS源,然后无法重新压缩它并检查两个版本,那么你的代码行现在不同步。

When it comes to source control and automated builds in the satisfying world of continuous integration (thank you CruiseControl.NET); hand compression will simply not do. The only way to maintain source control and offer compressed resources is to keep JS/CSS source & their minified brethren in a separate directory structure. Then register only one set of resources or the other in code-behind. However, if a developer makes a change to JS/CSS source and then fails to re-compact it and check in both versions, then you’re code-line is now out of sync. Not to mention inelegant.

我认为编写一个自定义的可执行文件(如果还没有存在)对于CC.NET任务块是很好的。在构建操作之后但在asp.net发布到目标之前,查找并压缩目标目录中的所有JavaScript和CSS资源。这样,开发人员只能处理JS和CSS源代码,用户只能获取缩减的资源。

I am thinking that it would be nice to write a custom executable (if one does not exist yet) for the CC.NET task block which would find and compress all JavaScript and CSS resources in the target directory after the build action but before the asp.net publish to target. This way, developers would only work on JS and CSS source and users would only get the minified resources.

有一个应用程序已经执行这个任务,如果不,我应该在构建服务器上安装哪种资源来执行CC.NET?

最近的问题我可以在这里找到这一个需要NAnt,这不是一个选项。)

(The closest question I could find here to this one required NAnt, which is not an option in my case.)

编辑
Dave Ward现在有一篇关于如何在Visual Studio中自动缩小

推荐答案

MSBuildCommunityTasks项目有几个MSBuild任务,可以做你正在寻找包括合并和JSCompress。

The MSBuildCommunityTasks Project has a few MSBuild tasks that may do what you are looking for including Merge and JSCompress.

您可以将这些添加到AfterBuild目标中的MSBuild项目中,以允许项目在每次构建项目时执行此操作,并且不会有任何不同步。然后,您的Web应用程序可以引用运行的压缩版本,但开发人员将编辑完整版本。

You could add these into your MSBuild project in the AfterBuild target to allow the project to perform this action every time the project is built and nothing would ever be out of sync. Your web application could then reference the compacted version for run but the developers would edit the full versions.

除了MSBuild社区任务程序集之外,服务器上不需要任何其他内容。你可以把这个程序集放在你自己的源代码树中,并从那里引用,你的CI构建应该得到那个程序集和构建它需要的所有东西。

Nothing else would be needed on the server except the MSBuild community tasks assembly. You can put this assembly in your own source tree and reference from there and your CI build should get that assembly and everything it needs when it builds.

这篇关于脚本缩小和与MSBuild的持续集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆