简体   繁体   English

如何为javascript库创建参考?

[英]How can I create a reference for javascript library?

I created a plugin-based web application, each one of the plugins is completely an independent web project also I created my own javascript library in the host application that should be used in every plugins, so I want to create a reference for my javascript library to use in every plugin project for getting intellisense in visual studio environment at development time. 我创建了一个基于插件的Web应用程序,每个插件完全是一个独立的Web项目,而且我在主机应用程序中创建了自己的javascript库,每个插件都应使用该javascript库,因此我想为我的javascript库创建引用在开发时在每个插件项目中使用,以在Visual Studio环境中获得智能感知。

Is there any best practice to be used for this issue? 有什么最佳实践可用于此问题?

You can use Reference tag on visual studio. 您可以在Visual Studio上使用参考标记。 There are four usage patterns: 有四种使用模式:

1- to reference another javascript file use 1-引用其他javascript文件使用

/// <reference path="someFolder/someScriptFile.js" />

2- reference to a Web Service 2-引用Web服务

/// <reference path="somepath/WCFService.svc" />
/// <reference path="somepath/asmxService.asmx" />

3- reference ta Web Page 3-参考ta网页

/// <reference path="somepath/default.aspx" />

4- reference to an Embedded Resource 4-参考嵌入式资源

/// <reference name="resource-name" />
/// <reference name="resource-name" assembly="assembly-name" />

Note : You can use app-relative paths (~/folder/file) to make your references more robust 注意 :您可以使用应用程序相对路径(〜/ folder / file)使您的引用更可靠

Hope it helps. 希望能帮助到你。

update: you can use it in .html, .aspx, .cshtml and .js files. 更新:您可以在.html,.aspx,.cshtml和.js文件中使用它。

Update2: if the path is not in your project you can add an existing file as a LinkedItem in visual studio (Add As Link) and add the LinkItem path to the path of reference tag. Update2:如果路径不在您的项目中,则可以在Visual Studio中将现有文件添加为LinkedItem (添加为链接),然后将LinkItem路径添加到引用标记的路径。

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

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