简体   繁体   English

Visual Studio 2019 Javascript - 如何引用应用程序根相对路径?

[英]Visual Studio 2019 Javascript - how to reference application root relative path?

Per the old Visual Studio 2015 docs, we could use "~" to reference the application root path:根据旧的 Visual Studio 2015 文档,我们可以使用“~”来引用应用程序根路径:
https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2015/ide/javascript-intellisense?view=vs-2015&redirectedfrom=MSDN#ReferenceDirectives https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2015/ide/javascript-intellisense?view=vs-2015&redirectedfrom=MSDN#ReferenceDirectives

So we could use a reference path like this:所以我们可以使用这样的参考路径:
/// <reference path='~/my/common/helpers/file.js' />

In any other JS file (lets say ~/some/other/path/file2.js), and it would always resolve regardless of where it was, relatively.在任何其他 JS 文件中(比如说 ~/some/other/path/file2.js),无论它在哪里,它总是会相对解析。 Now in VS2019 (and I believe also in VS2017), this doesn't work, and warns:现在在 VS2019 中(我也相信在 VS2017 中),这不起作用,并警告:

TS6053... not found. TS6053...未找到。

These reference paths still work if you remove the "~" and fix the path to be relative, but then it's unique/relative to the individual file (which means every file might be different - we can't just copy-paste throughout).如果您删除“~”并将路径修复为相对路径,这些参考路径仍然有效,但它是唯一的/相对于单个文件(这意味着每个文件可能不同 - 我们不能只是复制粘贴)。 For this project, we're still using plain old JS, no modules or TS.对于这个项目,我们仍然使用普通的旧 JS,没有模块或 TS。 Does anyone know a workaround to use an application root relative path in VS2019?有谁知道在 VS2019 中使用应用程序根相对路径的解决方法?

I think VS2017 and VS2019 does not support ~ application-root-relative path so far.到目前为止,我认为VS2017VS2019不支持~ application-root-relative 路径。 And I am not sure whether it is an issue or the Team has forgotten it because I got the same behavior as you described.而且我不确定这是一个问题还是团队已经忘记了它,因为我遇到了与您描述的相同的行为。

I have reported it to our DC Forum .And you can vote it and add any comments if I did not describe it in detail. 我已经向我们的 DC 论坛报告了它。如果我没有详细描述它,你可以投票并添加任何评论。 More votes will help get more attention from Microsoft .更多的投票将有助于获得微软的更多关注。

Since the process takes a long time, so far, as a suggestion, you have to use the full path of the js file like this on VS2019:由于该过程需要很长时间,因此到目前为止,作为建议,您必须在VS2019上使用这样的js文件的完整路径:

/// <reference path='C:\xxx\my\common\helpers\file.js' />

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

相关问题 Javascript 断点在 Visual Studio 2019 asp.net 应用程序中不起作用 - Javascript breakpoint not work in Visual Studio 2019 asp.net application 如何让Visual Studio使用别名而不是相对路径导入javascript模块? - How to get Visual Studio to import javascript modules using alias instead of relative path? hta/ javascript 如何使用相对路径执行应用程序 - hta/ javascript How to execute an application with relative path 如何获得相对路径的 Visual Studio 智能感知 - How can I get Visual Studio intellisense for the relative path 如何使用visual studio 2019和javascript从api获取数据? - How to get data from api using visual studio 2019 and javascript? 如何将 javascript 文件添加到 Visual Studio Community 2019 typescript 项目 - How add javascript files to Visual Studio Community 2019 typescript project Visual Studio 2019 Javascript XML 评论未显示 - Visual Studio 2019 Javascript XML Comments not showing Visual Studio 2019 中的 aspx Javascript Illustrator - Javascript illustrator for aspx in visual studio 2019 在JavaScript中获取应用程序的根路径 - Get root path of application in javascript 如何在MVC应用程序中从JavaScript解析相对路径 - How to resolve relative path from JavaScript within MVC application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM