シナリオは次のとおりです。
- Visual Studio を開きます。これはVS2010 Proで行われました。
- Visual Studio 内で F# Interactive を開く
- fsx ファイルでプロジェクトを開く
注: プロジェクトと fsx ファイルはE:\<directories>\fsharp-tapl\arith
fsx ファイルから F# Interactive にコマンドを送信する
> System.Environment.CurrentDirectory;; val it : string = "C:\Users\Eric\AppData\Local\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
#r コマンド エラーは、現在 F# Interactive が arith.exe の場所を認識していないことを示しています。
> #I @"bin\Debug" --> Added 'E:\<directories>\fsharp-tapl\arith\bin\Debug' to library include path
そこで、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'
また、F# Interactive は、正しい絶対パスを報告する arith.exe を正しく検出します。
> open Main > eval "true;" ;; true val it : unit = ()
これにより、arith.exe が正しく検出され、ロードされ、動作することが確認されます。
では、現在のディレクトリは役に立たないため、F# Interactive #I コマンドはどのようにしてプロジェクト パスを認識したのでしょうか?
私が本当に求めているのは、F# Interactive 内からプロジェクトへのパスを取得する方法E:\<directories>\fsharp-tapl\arith
です。
編集
> printfn __SOURCE_DIRECTORY__;;
E:\<directories>\fsharp-tapl\arith
val it : unit = ()