使用 MSBuild 枚举文件夹
我即将进入 VS2008 / Framework 3.5 中的 Asp.Net MVC 1.0 项目的最后阶段,并尝试进行一些性能优化。在我的项目中,我使用了一些不同的“主题”,具体取决于登录用户的角色。我的主题文件夹结构如下...
\Themes
\Theme1
\Css
\Folder1
\CssFile1.css
\CssFile2.css
\Folder2
\CssFile1.css
\CssFile2.css
\Images
<Images go here>
\Theme2
\Css
\Folder1
\CssFile1.css
\CssFile2.css
\Folder2
\CssFile1.css
\CssFile2.css
\Images
<Images go here>
随着新客户的加入,新主题将添加到此文件夹结构中。
我正在使用雅虎! UI 库:.Net 的 YUI 压缩器 (这真的很酷)来缩小和合并我的 css(和 js)文件。
我按照 http://yuicompressor.codeplex 中的示例进行操作.com/wikipage?title=Sample%20MSBuild.xml%20File&ProjectName=yuicompressor 通过构建后事件运行 MSBuild 脚本来执行缩小/合并任务。
一切都很好,除了当我在 ItemGroup 中使用类似
来指定从何处获取 css 文件时,每个主题的所有 css 文件都合并到一个文件中,就像这样...
\Themes
\SylesSheetFinal.css
我想要的是仅合并主题下的 css,为每个主题创建一个 css 文件...
\Themes
\Theme1
\StyleSheetFinal1.css
\Theme2
\StyleSheetFinal2.css
我对 MSBuild 真的很陌生。有谁知道如何修改示例以自动遍历每个主题文件夹并为每个主题创建一个缩小/合并的样式表?主题可以经常添加或删除,因此我不想手动将每个主题路径包含到我的 ItemGroup 中。相反,我希望 MSBuild 脚本自动遍历主题根目录下的子文件夹,无论文件夹数量如何。
谢谢!
I am coming up on the end stages of an Asp.Net MVC 1.0 project in VS2008 / Framework 3.5, and trying to do some performance optimizations. In my project, I have a few different "themes" that are used, depending on the role of the logged in user. My themes folder structure is like so...
\Themes
\Theme1
\Css
\Folder1
\CssFile1.css
\CssFile2.css
\Folder2
\CssFile1.css
\CssFile2.css
\Images
<Images go here>
\Theme2
\Css
\Folder1
\CssFile1.css
\CssFile2.css
\Folder2
\CssFile1.css
\CssFile2.css
\Images
<Images go here>
As new customers come on board, new themes will be added to this folder structure.
I am using the Yahoo! UI Library: YUI Compressor for .Net
(which is really cool) to minify and merge my css (and js) files.
I followed the example at http://yuicompressor.codeplex.com/wikipage?title=Sample%20MSBuild.xml%20File&ProjectName=yuicompressor to run an MSBuild script via a post-build event to do the minify/merge tasks.
Everything works great, except that when I use something like <CssFiles Include="..\Themes\**\*.css" />
in my ItemGroup to specify where to get the css files, all css files from every theme are merged into one file, like this...
\Themes
\SylesSheetFinal.css
What I want instead is to merge only the css under the themes, creating one css file for each...
\Themes
\Theme1
\StyleSheetFinal1.css
\Theme2
\StyleSheetFinal2.css
I am really new to MSBuild. Does anyone know how I can modify the sample to automatically walk over each of the theme folders and create a minified/merged stylesheet for each? The themes can be added or removed quite often, so I don't want to have to manually include each theme path to my ItemGroup. Instead, I want the MSBuild script to walk the subfolders underneath the Themes root automatically, regardless of the number of folders.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您想要做的事情可以通过 批处理。批处理是为每个唯一批次执行一次特定任务(或目标)的过程。批处理有两种类型;任务批处理和目标批处理。根据此处提供的信息,任务批处理是最常见的,也是我认为您需要的。批处理可能有点令人困惑,但一旦掌握了它,也不算太糟糕。
批处理始终涉及
%()
运算符。以下是任务批处理的示例。输出将是:
在这篇文章中完全描述批处理太困难了,但我已经在 http://sedotech.com/Resources#Batching。
What you are trying to do can be accomplished with batching. Batching is the process of executing a specific task (or target) once for each unique batch. There are two types of batching; Task Batching and Target Batching. Task batching is the most common and what I think you need, based on the info provided here. Batching can be kind of confusing, but it is not too bad once you get a grasp on it.
Batching always involves the
%()
operator. Here is an example of Task Batching.The output would be:
It is too tough to fully describe batching in this post, but I've put together some really great resources available online at http://sedotech.com/Resources#Batching.