Guy*_*der 9 f# visual-studio f#-interactive
这是场景:
E:\<directories>\fsharp-tapl\arith从fsx文件向F#Interactive发送命令
> System.Environment.CurrentDirectory;;
val it : string = "C:\Users\Eric\AppData\Local\Temp"
Run Code Online (Sandbox Code Playgroud)
我没想到Temp目录,但它有意义.
> #r @"arith.exe"
Examples.fsx(7,1): error FS0082: Could not resolve this reference.
Could not locate the assembly "arith.exe".
Check to make sure the assembly exists on disk.
If this reference is required by your code, you may get compilation errors.
(Code=MSB3245)
Examples.fsx(7,1): error FS0084: Assembly reference 'arith.exe' was not found
or is invalid
Run Code Online (Sandbox Code Playgroud)
#r命令错误显示F#Interactive当前不知道arith.exe的位置.
> #I @"bin\Debug"
--> Added 'E:\<directories>\fsharp-tapl\arith\bin\Debug'
to library include path
Run Code Online (Sandbox Code Playgroud)
所以我们告诉F#Interactive arith.exe的位置.请注意,路径不是绝对路径,而是项目的子路径.我没有告诉F#Interactive arith项目的位置
E:\<directories>\fsharp-tapl\arith
> #r @"arith.exe"
--> Referenced 'E:\<directories>\fsharp-tapl\arith\bin\Debug\arith.exe'
Run Code Online (Sandbox Code Playgroud)
并且F#Interactive正确地发现arith.exe报告了正确的绝对路径.
> open Main
> eval "true;" ;;
true
val it : unit = ()
Run Code Online (Sandbox Code Playgroud)
这确认arith.exe已正确找到,加载并正常工作.
那么F#Interactive #I命令如何知道项目路径,因为当前目录没有帮助?
我真正追求的是来自F#Interactive,如何获得项目的路径,E:\<directories>\fsharp-tapl\arith.
编辑
> printfn __SOURCE_DIRECTORY__;;
E:\<directories>\fsharp-tapl\arith
val it : unit = ()
Run Code Online (Sandbox Code Playgroud)
pad*_*pad 17
在F#Interactive中,要搜索的默认目录是源目录.您可以使用它轻松查询__SOURCE_DIRECTORY__.
允许您使用相对路径,此行为非常方便.您经常在fsx文件所在的文件夹中包含fs文件.
#load "Ast.fs"
#load "Core.fs"
Run Code Online (Sandbox Code Playgroud)
当您引用相对路径时,F#Interactive将始终使用隐式源目录作为起始点.
#I ".."
#r ... // Reference some dll in parent folder of source directory
#I ".."
#r ... // Reference some dll in that folder again
Run Code Online (Sandbox Code Playgroud)
如果你想记住下一个引用的旧目录,你应该使用#cd:
#cd "bin"
#r ... // Reference some dll in bin
#cd "Debug"
#r ... // Reference some dll in bin/Debug
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4447 次 |
| 最近记录: |