在 Visual Studio 2010 中处理常见的 JavaScript 文件 [英] Handling common JavaScript files in Visual Studio 2010

查看:28
本文介绍了在 Visual Studio 2010 中处理常见的 JavaScript 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在着手开发几个完全依赖 JavaScript 的网络应用程序(我们之前的应用程序是 ASP.NET MVC,JavaScript 的优点"洒在顶部).

We're beginning work on a couple of fully JavaScript-dependent web apps (our previous apps have been ASP.NET MVC, with JavaScript 'goodness' sprinkled over-the-top).

我们有一些文件将被全面共享,最好将这些文件存储在一个公共项目中,并将它们添加为链接"到单独的项目中(就像编译代码一样).

We have a few files that will be shared across the board, and it would be nice to store these files in a Common project, and 'Add As Link' them into individual projects (as would be possible with compiled code).

显然这不适用于 JavaScript 之类的东西,因为文件实际上不在正确的位置.

Obviously this doesn't work with something like JavaScript as the file isn't actually 'there' in the correct location.

有没有人有关于保留一个共享 JavaScript 文件的单一版本以供多个项目使用的建议?

推荐答案

最后,我就是这样实现的.这可能不是每个人的口味 - 但对我来说是一种享受.

In the end, this is how I've achieved it. It may not be to everyone's taste - but worked a treat for me.

注意:在我们所有的项目中,静态资源都位于名为Assets"的根目录中,因此例如 JavaScript 始终位于/Assets/js/和 CSS/Assets/css/中.

Note: In all of our projects, static resources are in a root directory called 'Assets', so for example JavaScript is always in /Assets/js/ and CSS /Assets/css/.

解决方案

  1. 在要导入"通用代码的项目中,我只需在/Assets/js/中添加通用 .js 文件作为链接".
  2. 转到新添加的属性并将复制到输出目录"设置为如果更新则复制".
  3. 现在我只需将项目的构建后事件命令行编辑为以下内容:xcopy/Y/E "$(TargetDir)Assets" "$(ProjectDir)Assets"

当项目构建时,它会将导入的文件复制到 inAssetsjs - 构建后事件然后将这些文件的副本复制到项目目录 - 及时让站点使用它们.

When the project builds, it copies the imported files to inAssetsjs - the post-build event then takes a copy of those over to the project directory - in time for the site to use them.

这篇关于在 Visual Studio 2010 中处理常见的 JavaScript 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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