Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 519
Levenlol Avatar asked Nov 01 '15 23:11

Levenlol


2 Answers

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
like image 119
mavnn Avatar answered Oct 21 '22 08:10

mavnn


I've been dealing with .fsx scripts so much, lately, for DevOps tasks, that I found myself in need of this, to:

  1. Check the correctness of my scripts via CI, to not break them by mistake as I do changes to them.
  2. Get them to execute faster

So then I've decided to embark myself in automating what @mavnn explained in his answer.

It's so meta that my tool to compile scripts is a script itself (so it can compile itself and therefore not incur in performance impact if you want to use it for the sake of performance).

I'm working on this project in the open and I've published it here in GitLab. Contributions welcome.

like image 7
knocte Avatar answered Oct 21 '22 08:10

knocte