Here is the scenario:
- Open Visual Studio. This was done in VS2010 Pro.
- Open F# Interactive within Visual Studio
- Open project with fsx file
Note: Project and fsx file are inE:\<directories>\fsharp-tapl\arith
Send commands to F# Interactive from fsx file
> System.Environment.CurrentDirectory;; val it : string = "C:\Users\Eric\AppData\Local\Temp"
I was not expecting a Temp directory but it makes sense.
> #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
The #r command error shows that F# Interactive currently does not know the location of arith.exe.
> #I @"bin\Debug" --> Added 'E:\<directories>\fsharp-tapl\arith\bin\Debug' to library include path
So we tell F# Interactive the location of the arith.exe. Notice that the path is NOT an absolute path but a sub-path of the project. I have not told F# Interactive the location of the arith project
E:\<directories>\fsharp-tapl\arith
> #r @"arith.exe" --> Referenced 'E:\<directories>\fsharp-tapl\arith\bin\Debug\arith.exe'
And F# Interactive correctly finds arith.exe reporting the correct absolute path.
> open Main > eval "true;" ;; true val it : unit = ()
This confirms that arith.exe was correctly found, loaded and works.
So how did F# Interactive #I command know the project path since the current directory is of no help?
What I am really after is from within F# Interactive how does one get the path to the project, E:\<directories>\fsharp-tapl\arith
.
EDIT
> printfn __SOURCE_DIRECTORY__;;
E:\<directories>\fsharp-tapl\arith
val it : unit = ()