Search code examples
compilationf#releasef#-interactive

f# how can i compile and then release a file .fsx


Hi I've made a simple program in f# and windows forms, how can I build the exe and then send it to friends for testing ? In the debug folder i found nothing.


Solution

  • It is possible to create an executable from an FSX file, but this scenario is not supported by Visual Studio out of the box. If you've reached this stage because you're using F# for the first time, and the difference between fsx and fs files was unclear I'd recommend turning your code into an .fs file and going from there.

    If you have a reason to compile an fsx file (there are some!), then read on...

    The F# compiler itself is perfectly happy to accept FSX files as source files, but you do need to play a few tricks.

    Firstly, if you have any #load or #r lines in your script files, you will need to wrap them in a #if INTERACTIVE block.

    Secondly, you must now manage feeding the compiler command line executable all of the relevant references and your code files in the correct order: remember that F# is an order dependent language.

    You can find the compiler options on MSDN, although it's worth noting that if you're using the open source build of F# the compiler is called fsharpc rather than fsc as it is in the Visual Studio install.

    So you're likely to end up running a command that looks something like this:

    fsc.exe -r System.Xml --target:exe myProgram.exe MyScript.Things.fsx MyScript.fsx