脚本缩小和与 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 任务块编写一个自定义可执行文件(如果尚不存在)会很好,该任务块将在构建操作后查找并压缩目标目录中的所有 JavaScript 和 CSS 资源,但是在 asp.net 发布到目标之前.这样,开发者只需要处理 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 中自动缩小在他的网站上.
Dave Ward now has a great article on how to automatically minify in Visual Studio at his site.
推荐答案
MSBuildCommunityTasks 项目有一个一些 MSBuild 任务可能会满足您的需求,包括 Merge 和 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.
相关文章