Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to launch an F# console app from VS Code

Given a simple F# console app:

[<EntryPoint>]
let main argv =
    printfn "Hello  world"
    Console.ReadLine() |>  ignore
    0

What do I need to do to start the console app up in the same manner that ctrl F5 would do in Visual Studio. I have tried running it form a FAKE build script using the Fake.ProcessHelper:

Target "Run" (fun _ ->     

        let exe = @"C:\Source\code\fs_console_app\build\fs_console_app.exe"
        let errorCode = Shell.AsyncExec(exe, "", buildDir)
        ()    
    )

Hitting Ctrl F5 I receive the following build report:

Target     Duration
------     --------
Build      00:00:00.3916039
Run        00:00:00.0743197
Total:     00:00:00.5605493
Status:    Ok

But no sign of the console application starting up and waiting for input.

like image 973
Michael McDowell Avatar asked Sep 12 '16 21:09

Michael McDowell


1 Answers

I would have preferred to comment but it would be too long, I consider this more of a workaround answer, as I'm not that familiar with Fake. My guess is that your Run Target is actually being executed but is probably being swallowed by AsyncExec or it just shows in the Fake output window (try Exec) but doesn't start a new window.

You can just create a runcmd.bat (assuming you're on windows), and put the following into it, make sure the file is NOT in your build directory as it might get cleaned up:

start C:\Source\code\fs_console_app\build\fs_console_app.exe

You need start to kick off a new cmd window. This could be something else of course, bash or powershell, etc.

Then inside your build.fsx:

Target "Run" (fun _ ->     

        let exe = "path/to/runcmd.bat"
        printfn "%A" "Hello World"
        Shell.Exec(exe) |> ignore

    )

// Build order
"Clean"
  ==> "Build"
  ==> "Run"
  ==> "Deploy"

Now if I run (via Ctrl+Shift+P) Fake, and pick Run, it compiles, starts a new command line and waits for the ReadLine. It also works via Ctrl+F5.

like image 135
s952163 Avatar answered Nov 12 '22 18:11

s952163