fsprojects / FAKE

FAKE - F# Make
https://fake.build
Other
1.28k stars 586 forks source link

Fake does not find dotnet fsi for Fsi.exec targets. #2561

Closed nhirschey closed 3 years ago

nhirschey commented 3 years ago

Description

Fake does not find new versions of fsi on windows. FsiTool.Internal works, but FsiTool.Default and FsiTool.External "dotnet fsi" fail.

Repro steps

  1. Install a new version of fsi
    • If installed via Visual Studio 2019 16.8 Community, it will be in [ProgramFilesX86]/Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\FSharp
    • If installed via dotnet 5.0.100 it will be in [ProgramFiles]dotnet\sdk\5.0.100\FSharp.
  2. Try to run Fsi.exec id "testscript.fsx" [] or Fsi.exec (fun p -> {p with FsiTool.External "dotnet fsi"}) "testscript.fsx" [] in a fake build.fsx script.

    Expected behavior

I expect fake to run testscript.fsx

Actual behavior

The target fails with the error (Start of process 'fsi.exe' failed.) or (Start of process 'dotnet fsi' failed.).

The problem is the fsi path searching here: https://github.com/fsharp/FAKE/blob/release/next/src/app/Fake.DotNet.Fsi/Fsi.fs#L249

To find the latest dotnet fsi, it will probably be necessary to update ProcessUtils.findFilesInternal so that it searches C:\Program Files\dotnet\sdk for the latest sdk.

Known workarounds

Fsi.exec (fun p -> {p with FsiTool.Internal}) "testscript.fsx" [] works.

Related information

github-actions[bot] commented 3 years ago

Welcome to the FAKE community! Thank you so much for creating your first issue and therefore improving the project!

github-actions[bot] commented 3 years ago

There has not been any activity in this issue for the last 3 months so it will be closed in 14 days if there is no activity.

nhirschey commented 3 years ago

still an issue

rynoV commented 6 months ago

Update: Actually it seems like the below issue was just because I was using the wrong TargetProfile


I'm also running into this issue. In my case FsiTool.Internal also doesn't work

Starting task 'Fsi ': internal fsi with args ["C:\fsi.exe"; "--load:snap_dataset.fsx"; "--debug:pdbonly";
 "--targetprofile:mscorlib"; "--exec"; "--"]
Unhandled exception. Fake.Core.BuildFailedException: Target 'CheckSnapDataset' failed.
 ---> System.AggregateException: One or more errors occurred. (Error creating evaluation session: StopProcessingExn)
 ---> System.Exception: Error creating evaluation session: StopProcessingExn
   at Microsoft.FSharp.Core.PrintfModule.PrintFormatToStringThenFail@1448.Invoke(String message)
   at FSharp.Compiler.Interactive.Shell.FsiEvaluationSession..ctor(FsiEvaluationSessionHostConfig fsi, String[] argv, TextReader inReader, TextWriter outWriter, TextWriter errorWriter, Boolean fsiCollectible, FSharpOption`1 legacyReferenceResolver) in D:\a\_work\1\s\src\fsharp\fsi\fsi.fs:line 3262
   at Fake.DotNet.Fsi.InternalFsi.doExec(String script, FSharpList`1 allArgs) in D:\a\FAKE\FAKE\src\app\Fake.DotNet.Fsi\Fsi.fs:line 394
   at Fake.DotNet.Fsi.InternalFsi.exec(String script, FSharpList`1 allArgs) in D:\a\FAKE\FAKE\src\app\Fake.DotNet.Fsi\Fsi.fs:line 408
   at Fake.DotNet.Fsi.execRaw(FSharpFunc`2 fsiParams, String script, FSharpList`1 scriptArgs) in D:\a\FAKE\FAKE\src\app\Fake.DotNet.Fsi\Fsi.fs:line 429
   at Fake.DotNet.Fsi.exec(FSharpFunc`2 fsiParams, String script, FSharpList`1 scriptArgs) in D:\a\FAKE\FAKE\src\app\Fake.DotNet.Fsi\Fsi.fs:line 460

Seems related to https://github.com/fsharp/fsharp-compiler-docs/issues/807 and maybe https://github.com/dotnet/fsharp/issues/11770

rynoV commented 6 months ago

Internal doesn't seem to respect WorkingDirectory

I hacked External like this for now

diff --git a/Build/Fsi.fs b/Build/Fsi.fs
--- a/Build/Fsi.fs  (revision eb8500c3ee49ba79594a49077974bd2f9e0f935c)
+++ b/Build/Fsi.fs  (date 1711662199284)
@@ -49,6 +48,7 @@

     [<RequireQualifiedAccess>]
     type FsiTool =
+        /// Use an empty string to use `dotnet fsi`
         | External of string
         | Internal
         | Default
@@ -357,7 +357,7 @@

             let messageF msg = results.Add msg

-            let processResult =
+            let mutable proc =
                 CreateProcess.fromRawCommandLine fsiExe args
                 |> CreateProcess.withEnvironment (
                     defaultEnvironmentVars |> List.append (parameters.Environment |> Map.toList)
@@ -366,7 +366,11 @@
                 |> CreateProcess.withTimeout TimeSpan.MaxValue
                 |> CreateProcess.redirectOutput
                 |> CreateProcess.withOutputEventsNotNull messageF errorF
-                |> Proc.run
+
+            if String.IsNullOrWhiteSpace fsiExe then
+                proc <- proc |> DotNet.prefixProcess id [ "fsi" ]
+
+            let processResult = proc |> Proc.run

             if processResult.ExitCode <> 0 then
                 List.iter Trace.traceError (errors |> List.ofSeq)