简体   繁体   English

在同一解决方案中包括来自其他项目的javascript文件

[英]Including javascript files from other projects inside the same solution

I have a project called WebResources where I have all the JS files that I intend to use in 2 other projects (all three projects sit in the same solution). 我有一个名为WebResources的项目,其中有我打算在其他2个项目中使用的所有JS文件(所有三个项目都位于同一解决方案中)。

I just spent 2 hours playing around with the file paths and VS just doesn't see the JS file (unless I specify the full path with the drive letter). 我只花了2个小时来处理文件路径,而VS却没有看到JS文件(除非我用驱动器号指定完整路径)。 Is there a trick to including javascript files relatively from other projects? 是否有一个技巧可以相对包含其他项目中的javascript文件?

My file structure is something like: 我的文件结构是这样的:

Project1
  Default.aspx
Project2
WebResourcesProject
   /js
     testToInclude.js

No matter how I try to include testToInclude.js inside Default.aspx, VS doesn't see it. 无论我如何尝试在Default.aspx中包含testToInclude.js,VS都不会看到它。

Any ideas? 有任何想法吗?

To include relatively a file like as an image, css or js, they should be placed in the same server. 相对包括文件等作为图像,CSS或JS,它们应该被放置在相同的服务器。

Let's say your server root is http://localhost:8080/ , and you map each project to separate folders such as http://localhost:8080/WebResourcesProject/ and http://localhost:8080/Project1/ then you could include the js like this (from the default.aspx file): 假设您的服务器根目录为http:// localhost:8080 / ,并且将每个项目映射到单独的文件夹,例如http:// localhost:8080 / WebResourcesProject /http:// localhost:8080 / Project1 /,则可以包含像这样的js(来自default.aspx文件):

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

You can easily try that if you deploy your projects into your local IIS. 如果将项目部署到本地IIS中,则可以轻松尝试。 If you're using the development webserver that visual studio give us, it seems to be not that easy. 如果您使用的是Visual Studio提供给我们的开发网络服务器,那似乎并不容易。 If there is not any real need of having the projects separately or referencing files relatively, I would consider either merging them or making absolute references. 如果没有单独具有的项目或引用相对文件任何真正的需要,我会考虑要么把它们合并或进行绝对引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM