将 Microsoft Ajax Minifier 与 Web 安装项目结合使用源代码控制

发布于 2024-08-22 15:46:36 字数 730 浏览 8 评论 0原文

我刚刚开始研究 Microsoft Ajax Minifer 4.0 与 Visual Studio 2008 一起使用我正在开发的网络应用程序。事实证明,将其挂接到 .csproj 文件中非常容易,因此它为所有脚本生成 .min.js 文件,但是我对如何将其与 Web 设置项目集成感到困惑。源代码控制。

本质上,我想做的是将生成的 .min.js 文件包含在 Web 安装项目中,而不将它们包含在源代码管理中,因为:

  1. 在执行构建之前必须检查它们是一种痛苦(压缩器无法修改它们)如果他们没有签出)。
  2. 由于它们是作为“构建工件”创建的,因此将它们存储在源代码控制下似乎是错误

到目前为止,我遇到的唯一选择是通过右键单击 Web 安装项目并选择“添加 > 文件”,然后将相关的 .min.js 文件明确包含在安装项目中文件夹层次结构在“目标计算机上的文件系统”中重复,以便我可以强制文件到正确的位置。这既不优雅也不简单/健壮,因为:

  1. 它需要我手动将每个缩小的 js 文件手动添加到 Web 设置项目
  2. 中在 Web 应用程序项目和 Web 设置项目中维护相关目录结构的副本
  3. 记住添加任何新的 js 文件缩小版本到 Web 安装项目

有更好的方法吗?

I've just started investigating the Microsoft Ajax Minifer 4.0 for use with a Visual Studio 2008 Web Application I work on. It's proven easy enough to hook it into the .csproj file so it produced .min.js files for all scripts, however I'm stumped as to how to integrate this with the Web Setup project & Source Control.

Essentially what I want to do is have the resultant .min.js files included in the Web Setup project without having them included in Source Control because:

  1. Having to check them out prior to the build being executing is a pain (the minifier cannot modify them if they're not checked out).
  2. As they're created as a "build artifact" it just seems wrong to have them stored under source control.

The only option I've managed to come across so far is to explicitly include the .min.js files as part of the Setup project by right clicking on the Web Setup project and choosing "Add > File", and then having the relevant folder hierarchy duplicated in "File System on Target Machine" so that I can force the file to the correct location. This is neither elegant or simple/robust as:

  1. It requires me to manually add every minified js file to the Web Setup project by hand
  2. Maintain a copy of the relevant directory structure in both the Web Application project and the Web Setup project
  3. Remember to add any new js files minified versions to the Web Setup project

Is there a better way of doing this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

故事未完 2024-08-29 15:46:36

我最终选择的解决方案是在我的项目中包含 minifier DLL 并创建一个处理程序 (.ashx),我已将其替换为对 .js 文件的所有引用,因此:

<script src="MyJsFile.js" type="text/javascript"></script>

替换为

<script src="Minifier.ashx?file=MyJsFile.js" type="text/javascript"></script>

我的 web.config 文件,允许我确定脚本文件是否被压缩。

The solution I eventually opted for was to include the minifier DLL in my project and create a handler (.ashx) that I've replaced all references to .js files with, so:

<script src="MyJsFile.js" type="text/javascript"></script>

Is replaced with

<script src="Minifier.ashx?file=MyJsFile.js" type="text/javascript"></script>

I have a configuration setting in my web.config file that allows me to determine whether script files are minifed or not.

拔了角的鹿 2024-08-29 15:46:36

将 Microsoft Ajax Minifier 与源代码管理结合使用

Microsoft Ajax Minifier 生成
缩小的 JavaScript 和 CSS 文件
作为构建过程的输出。
为此,我们建议您
准确地处理缩小的文件
与您处理的方式相同
构建生成的程序集
过程。我们特别推荐
你不包括缩小的
Visual Studio 项目中的文件
并且您不检查缩小的
文件进入源代码管理。

如果您将缩小的文件包含在
您的项目,并且您使用源代码
控制,那么你会遇到
问题。当文件被签出时
源代码控制,它们被检查
去掉它们的只读属性
放。如果您尝试进行构建,
Microsoft Ajax Minifier 将生成
尝试写入时出错
只读文件。

来源: Microsoft

根据我的理解,这意味着不要将 -min 文件添加到项目,就是这样。当 IIS 构建应用程序时,它将自动创建文件。我认为您必须在 Web 服务器上安装 Microsoft Minifier 4.0。

Using the Microsoft Ajax Minifier with Source Control

The Microsoft Ajax Minifier generates
the minified JavaScript and CSS files
as the output of the build process.
For this reason, we recommend that you
handle the minified files in exactly
the same way as you would handle the
assemblies generated by the build
process. In particular, we recommend
that you do not include the minified
files in your Visual Studio project
and that you do not check the minified
files into source control.

If you include the minified files in
your project, and you use source
control, then you will encounter
problems. When files are checked out
of source control, they are checked
out with their read-only attributes
set. If you attempt to do a build, the
Microsoft Ajax Minifier will generate
an error when it attempts to write to
a read-only file.

source : Microsoft

From my understanding, this means do not add the -min files to the project, that's it. When IIS will build the app, it will create the files automatically. I think you must have Microsoft Minifier 4.0 to be installed on the web server tho.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文