简体   繁体   English

配置Visual Studio 2008以编辑旧版JScript ASP文件

[英]Configuring Visual Studio 2008 to edit legacy JScript ASP files

I'm working on a project that combines .NET with some legacy ASP code via COM interop. 我正在一个通过COM互操作将.NET与一些旧式ASP代码结合在一起的项目。 The legacy ASP is written in JScript - files look like this helloworld.asp example. 旧版ASP用JScript编写-文件看起来像下面的helloworld.asp示例。

<%@Language="JScript"%>
<html>
<head>
  <title>Jscript ASP Page</title>
</head>
<body>
  <h1>JScript ASP</h1>
  <p>This is JScript ASP at <%=new Date()%></p>
  <%
  var helloWorld = Server.CreateObject("Interop.HelloWorld")
  helloWorld.Name = "Dylan"
  %>
  <%=helloWorld.SayHello() %>
  </body>
</html>

I'd really like to use VS2008 to edit the legacy ASP code along with the rest of the project, but the Intellisense is behaving extremely strangely. 我真的很想使用VS2008与项目的其余部分一起编辑遗留的ASP代码,但是Intellisense的表现却异常奇怪。 One minute it'll be giving me the correct JScript keywords and methods: 一分钟,它将为我提供正确的JScript关键字和方法:

JS Intellisense in VS2008 - working http://www.dylanbeattie.net/vs_js_working.jpg VS2008中的JS Intellisense-工作http://www.dylanbeattie.net/vs_js_working.jpg

...so I'll type a line, press Enter, start typing the next line, and the exact same keystrokes will give me what appears to be VBScript intellisense instead: ...所以我将键入一行,按Enter,开始键入下一行,完全相同的击键操作将为我显示VBScript intellisense:

ASP intellisense in VS2008 - broken http://www.dylanbeattie.net/vs_js_wrong.jpg VS2008中的ASP智能感知-损坏的http://www.dylanbeattie.net/vs_js_wrong.jpg

Is there any way I can tell VS that .asp files are ALWAYS Javascript code, and never to use VB code at all? 有什么办法可以告诉VS .asp文件始终是Javascript代码,而从不使用VB代码? Having the IDE turn "var" into "vArray" when you press Enter is proving a little frustrating... 当您按下Enter键时,让IDE将“ var”转换为“ vArray”被证明有点令人沮丧...

Help me, Stackoverflow. 帮帮我,Stackoverflow。 You're my only hope. 你是我唯一的希望。

Classic ASP intellisense is, as you've observed, broken in VS2008. 如您所见,经典ASP intellisense在VS2008中已损坏。 Microsoft actually completely cut support for Classic ASP syntax coloring and intellisense in VS2008 RTM, then restored it in SP1 due to outcry from customers. 实际上,Microsoft完全切断了VS2008 RTM中对Classic ASP语法着色和智能感知的支持,然后由于客户的强烈反对,在SP1中将其还原。 Take a look at this bug report on the Microsoft Connect site for more info on how it got restored. 请查看Microsoft Connect网站上的此错误报告 ,以获取有关如何还原的更多信息。

Anyway, let me detail exactly how it's broken. 无论如何,让我详细说明它是如何损坏的。 What you're seeing is not actually VB intellisense-- instead, you're seeing methods and objects which are present in any of the following: 您所看到的实际上不是VB智能感知-而是看到以下任何一种中存在的方法和对象:

  • the server-side Response object sometimes other server-side objects like Session or Request, as if there were a javascript "with" statement for these objects before any of your code. 服务器端Response对象,有时还有其他服务器端对象,例如Session或Request,好像在任何代码之前都存在这些对象的javascript“ with”语句一样。 this makes no sense-- it's a bug in VS. 这没有意义-这是VS中的错误。
  • the client-side window object (!!!!). 客户端窗口对象 (!!!!)。 This makes no sense since this is server-side script. 这是没有意义的,因为这是服务器端脚本。 it's a bug in VS. 这是VS中的错误。
  • javascript keywords and global objects like String. javascript关键字和全局对象(如String)。 This is expected (although if you define your script using runat=server, it works more reliably-- if I define the script with <% %> I often don't get proper keyword intellisense. 这是预期的结果(尽管如果您使用runat = server定义脚本,则它的工作更可靠-如果我使用<%%>定义脚本,我通常不会获得正确的关键字intellisense。

Note that none of these are VB Intellisense-- what you're seeing are simply PascalCased methods of valid built-in methods of the Request, Response, etc. objects built into Classic ASP's server-side script object model. 请注意,这些都不是VB Intellisense,您所看到的只是PascalCased方法,这些方法是内置在Classic ASP服务器端脚本对象模型中的Request,Response等对象的有效内置方法。

Anecdotally, I've found intellisense to work much more naturally in runat=server script blocks than <% %> blocks. 有趣的是,我发现intelisense在runat = server脚本块中比<%%>块更自然地工作。 At least with runat=server, I get intellisense for typing "Request.", "Response.", etc. and also jscript keyword intellisense seems to work better in those blocks too. 至少在runat = server上,我通过键入“ Request。”,“ Response。”等获得了intellisense,而且jscript关键字intellisense在这些代码块中似乎也能更好地工作。

There are other quirks in intellisense, like when you have a <% %> script block, when you type a character, the character is ignored in the list of intellisense choices you get back. 智能感知中还有其他怪癖,例如当您具有<%%>脚本块时,当您键入一个字符时,在返回的智能感知选项列表中将忽略该字符。 (this also works better in runat=server blocks) (这在runat = server块中也更好)

In other words, this is all very broken. 换句话说,这都是非常糟糕的。 I have no inside information about why it's so busted, other than this is a feature which was deprecated in VS2008, brought back in a service pack, and likely has far less testing than other parts of VS-- so it's not surprising it's broken. 我没有内部原因了解其为何如此破败,除了此功能是VS2008中已弃用,引入了Service Pack并可能比VS其他部分进行的测试少得多的,因此它被打破并不奇怪。 Especially when you consider that it's supporting a feature, classic ASP, which Microsoft probably wants to go away. 尤其是当您考虑到它支持经典的ASP功能时,Microsoft可能会希望它消失。 That doesn't mean the Redmontonians are actively trying to sabotage this, but in a team with limited resources, making classic ASP work great is probably not going to attract the same level of attention as, for example, ASP.NET MVC. 这并不意味着Redmontonians正积极地破坏这一点,但是在一个资源有限的团队中,使经典的ASP出色地工作可能不会引起与ASP.NET MVC相同的关注。

That said, IMHO even this limited support is better than what was there in VS2008 RTM, when classic ASP files looked like notepad, wtih no intellisense or syntax coloring at all. 就是说,恕我直言,即使是这种有限的支持也比VS2008 RTM中的要好,当时经典的ASP文件看起来像记事本,根本没有智能感知或语法着色。

If you're annoyed at this sorry state of affairs, I'd suggest filing a bug report at https://connect.microsoft.com/VisualStudio . 如果您对这种令人遗憾的状况感到恼火,建议您在https://connect.microsoft.com/VisualStudio上提交错误报告。 Just like a bug report got Microsoft to restore classic ASP intellisense in VS2008 SP1, it might get them to fix it for SP2 and/or VS2010. 就像错误报告使Microsoft在VS2008 SP1中还原经典的ASP intellisense一样,它可能使他们为SP2和/或VS2010对其进行修复。 You might also want to check out the latest VS2010 beta to see if the problem is fixed or worse. 您可能还需要查看最新的VS2010 Beta,以查看问题是否已解决或更严重。

Sorry if this isn't the answer you were hoping for. 抱歉,这不是您想要的答案。 :-( :-(

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

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