28

I would like to use the F# interactive console with the projects in the currently open solution in Visual Studio 2010. Is there a quick and easy way to add a reference in the F# interactive console to reference projects in the currently open solution?

Russell
  • 17,481
  • 23
  • 81
  • 125

6 Answers6

30

I've got lines like this at the top of my .fs file:

#if INTERACTIVE
#r @"C:\path\to\some.dll"
#I @"C:\Users\bford\path\to\a\project\in\this\solution\bin\Debug"
#r "Project.name"
#endif

Alt-Enter now drops me into fsi with all the required stuff loaded

Ben Ford
  • 2,087
  • 21
  • 26
  • 1
    this answer would be terrific if it showed how, or worked with relative pathing – Maslow Sep 27 '15 at 15:07
  • I think this is now `Ctrl+Shift+Enter` by default and requires to select the contents of the file first. – Abel Dec 21 '16 at 19:14
20

I don't think there is any direct way to reference a project in the solution. The best way I can think of is to add a FSX file somewhere to your project with the #r directive:

#r @"bin\Debug\YourProject.dll"

Then you can at least reference the compiled DLL file simply by hitting Alt+Enter in Visual Studio. As far as I know, you cannot reference the project - you can only reference an assembly.

Currently, F# Interactive is really disconnected from the project system in Visual Studio. I suppose that closer integration would be quite useful (but probably difficult to provide).

Tomas Petricek
  • 240,744
  • 19
  • 378
  • 553
  • 4
    Hmmm, yeah I thought it would be half the point of having the F# interactive window in the IDE, would be to get some context of the IDE. Hopefully someone can shed some more light on this? – Russell Jun 06 '10 at 02:59
  • 3
    +1 Currently, F# Interactive is really disconnected from the project system in Visual Studio. – Guy Coder Feb 03 '13 at 13:20
  • I see a `send project output to F# interactive` menu item in solution explorer on F# projects, but not on C# projects =( – Maslow Jul 07 '16 at 14:08
20

If it's a project you reference often, you can add an 'always' reference to the FSI command line, under Tools->Options->F# Tools->F# interactive options. Add a -r switch like:

-r "C:\Users\yaddayadda\MyDll.dll"
Mau
  • 14,234
  • 2
  • 31
  • 52
16

Now in Visual Studio 2013 you can add a reference to the F# interactive window by right clicking on the referenced dll and clicking "Send to F# interactive".

JamesF
  • 402
  • 4
  • 9
1

I would think it should be straightforward to reference the current project, obtain the list of references it contains, and then optionally generate a list of #r (and possibly #i) statements for the interactive session being created, referencing the dll of the project itself as well.

For example: "fsi /i:pathOfLib1 /r:lib1 /i:pathOfLib2 /r:lib2 ...."

PS: base on the MSDN article it doesn't appear that library names can include their path prefixes hence the separate into /i and /i : http://msdn.microsoft.com/en-us/library/dd233172%28v=vs.100%29.aspx

George
  • 27
  • 2
1

It would be good if the Visual Studio F# Interactive Options menu allowed for the stipulation of a startup script that the invocation could pass to FSI via the "--use:" directive. Such a script could then be passed solution metadata that allows for the environments to be more integrated such as loading latest project outputs.

George
  • 2,451
  • 27
  • 37