本文介绍了.fsx和动态加载的程序集中的IntelliSense的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用#I#r在.fsx中动态引用程序集时,VS突出显示了导入类型的以下用法,并写道未定义名称空间或模块'XXX'".可以吗

When dynamically referencing assemblies in .fsx using #I and #r, VS highlights the following usages of imported types and writes "The namespace or module 'XXX' is not defined". Is it ok?

例如,在以下代码中

#I @".\Tools\FAKE"
#r "FakeLib.dll"

open Fake

Target "Hello" (fun _ -> trace "hello!")

Run "Hello"

VS突出显示Fake并说未定义名称空间或模块'Fake'",还突出显示了TargetRun.我在VS 2010 SP1和VS 11 CTP中有此问题.这个问题使得编写F#脚本比完成它更加困难.

VS highlights Fake and says "The namespace or module 'Fake' is not defined", it also highlights Target and Run. I have this problem in VS 2010 SP1 and in VS 11 CTP. This issue makes writing F# scripts a bit harder task than it could be.

顺便说一句,常见"类型的IntelliSence效果很好. FakeLib.dllFakeLib.xml位于.\Tools\FAKE目录中.该代码运行良好.

By the way, IntelliSence for "common" types works well. FakeLib.dll and FakeLib.xml are present in the .\Tools\FAKE directory. The code runs well.

更新1 这是情况的屏幕截图.您可以看到VS正确地(在工具提示中)解析了程序集FakeLib,同时Intellisense看到"了标准类型(工具提示在Console上).

Update 1Here's the screenshot of the situation. You can see that VS resolves assembly FakeLib correctly (in a tooltip), and that at the same time Intellisense "see" standard types (tooltip over Console) class.

更新2 我认为工作工作站上的IntelliSense出了点问题,因为它(IntelliSense)的行为本身很奇怪.当我启动VS并打开.fsx文件时,IntelliSense甚至拒绝解析标准类型/类,并且它不强调FAKE类,因此不执行任何操作.但是经过一段时间和对代码的某些操纵之后,IntelliSense才开始对标准类型起作用,并强调FAKE类型.

Update 2I think there's something wrong with the IntelliSense on my work workstation, because it (IntelliSense) behaves itself quite strange. When I start VS and open .fsx file, IntelliSense refuses to resolve even standard types/classes, and it doesn't underlines FAKE classes, it does nothing. But after some period of time and some manipulation over code IntelliSense starts working for standard types and underlines FAKE types.

此外,当我在家庭工作站上创建类似的代码时,没有问题,IntelliSense可以正常工作.

Moreover, when I've created the similar code on my home workstation there were no problems, IntelliSense works as it should.

推荐答案

如果将完整路径放入#r指令中,则会获得完整的IntelliSense. #I指令虽然方便,但可以阻止IntelliSense正常运行,尽管代码可以正常运行.对于松散的脚本和项目中的脚本都是如此.看看Tomas Petricek的[FSharp.AsyncExtensions](http://github.com/tpetricek/FSharp.AsyncExtensions]项目.

If you put the full path into the #r directive, you'll get full IntelliSense. The #I directive, while convenient, prevents IntelliSense from working properly though the code will run just fine. This is true for both loose scripts and those found in projects. Have a look at Tomas Petricek's [FSharp.AsyncExtensions](http://github.com/tpetricek/FSharp.AsyncExtensions] project.

这篇关于.fsx和动态加载的程序集中的IntelliSense的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 04:48