John
John

Reputation: 627

How to create a shortcut for F# compiler (Fsc.exe)?

I have a stupid question to ask. I have just started learning F#, and I am trying to compile some basics examples (such as HelloWorld.fs).

I created a simple F# file whose path is: C:\FSharp\HelloWorld.fs.

In order to compile it, I used the full path of the F# compiler as follows:

C:\FSharp>"C:\Program Files\Microsoft F#\v4.0\fsc.exe" HelloWorld.fs

It worked perfectly.

However, I do not want to keep writing the full path of the complier: C:\Program Files\Microsoft F#\v4.0\fsc.exe. I tried to add it to Windows path,but I keep getting the error fsc is not recognized as internal or external command.

How can I create a shortcut word for F# compiler so that I don't have to use the full path everytime I need to compile a program?

Upvotes: 2

Views: 4653

Answers (4)

pim
pim

Reputation: 12587

For those arriving here in 2019 having received F# as a component of Visual Studio 2017. The location of the F# compiler is as follows:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\CommonExtensions\Microsoft\FSharp\fsc.exe

Take careful note of the Version Type (Community in this case) and adjust yours accordingly.

Upvotes: 6

Harley Swick
Harley Swick

Reputation: 61

I tried setting it to my path, but unfortunately it did not work. Tried logging off/restarting etc. I believe it is because of security measures in place on my work computer.

For other people having similar issues, I found that setting the alias not only worked but was more preferable over other methods.

set-alias fsi "C:\Program Files (x86)\Microsoft SDKs\F#\3.1\Framework\v4.0\fsi.exe"
set-alias fsc "C:\Program Files (x86)\Microsoft SDKs\F#\3.1\Framework\v4.0\fsc.exe"

Now the commands don't have the annoying .exe file extension.

Helpful in getting setup was this article on creating persistent aliasing for powershell. http://www.powershellpro.com/powershell-tutorial-introduction/tutorial-powershell-aliases/

Upvotes: 2

Jack P.
Jack P.

Reputation: 11525

You don't really need to create a shortcut for this, you just need to add the folder containing fsc.exe to your PATH variable.

When you open the command prompt, run this:

set PATH=%PATH%;"C:\Program Files\Microsoft F#\v4.0\"

or, if you're using a 64-bit version of Windows:

set PATH=%PATH%;"C:\Program Files (x86)\Microsoft F#\v4.0\"

The most recent version of fsc.exe can be found in these locations :

  • "C:\Program Files (x86)\Microsoft SDKs\F#\3.1\Framework\v4.0" // as of Aug 2014

  • "C:\Program Files (x86)\Microsoft SDKs\F#\3.0\Framework\v4.0" // 2013

Upvotes: 3

Tomas Petricek
Tomas Petricek

Reputation: 243106

I can confirm that adding the directory to your PATH variable should do the trick (works on my machine!) Note that you may need to restart any opened command line (or, just to make sure, the system) until the change is taken into account if you change the PATH variable in system properties.

You could also create a bat file with something like:

echo off
"C:\Program Files (x86)\Microsoft F#\v4.0\fsc.exe" %*

And then make sure the bat file is somewhere in your PATH. But the bat file can have a different name (say fsharpc.bat), in case there is some name clash between the standard name fsc and something else on your system...

Upvotes: 1

Related Questions