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

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

问题描述

我们正在开始研究几个完全依赖JavaScript的Web应用程序(我们以前的应用程序已经是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).

我们有一些文件可以全面共享,将这些文件存储在Common项目中,并将它们添加为链接将它们放入单个项目中(这是可能的)已编译的代码)。

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文件As Link。 li>
  2. 转到新添加的属性并将复制到输出目录设置为如果更新则复制。

  3. 现在我只需将项目的构建后事件命令行编辑为以下内容:
    xcopy / Y / E$(TargetDir)\Assets$ (ProjectDir)\Assets

  1. In the project that is going to 'import' the common code, I simply add the common .js file 'As Link' within /Assets/js/.
  2. Go to that new addition's Properties and set 'Copy to Output Directory' to 'Copy if newer'.
  3. Now I simply edit the project's post-build event command line to the following: xcopy /Y /E "$(TargetDir)\Assets" "$(ProjectDir)\Assets"

项目构建时,会将导入的文件复制到\ bin \ Assets\js - 构建后事件然后将这些事件的副本带到项目目录中 - 以便网站使用它们。

When the project builds, it copies the imported files to \bin\Assets\js - 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天全站免登陆