@@ -353,24 +353,35 @@ module internal FSharpEnvironment =
353353 let getFSharpCoreLibraryName = " FSharp.Core"
354354 let fsiLibraryName = " FSharp.Compiler.Interactive.Settings"
355355
356- let getFSharpCompilerLocation () =
357- let location = Path.GetDirectoryName( typeof< TypeInThisAssembly>. Assembly.Location)
358- match BinFolderOfDefaultFSharpCompiler ( Some location) with
356+ let getFSharpCompilerLocationWithDefaultFromType ( defaultLocation : Type ) =
357+ let location =
358+ try
359+ Some ( Path.GetDirectoryName( defaultLocation.Assembly.Location))
360+ with | _ ->
361+ None
362+ match BinFolderOfDefaultFSharpCompiler ( location) with
359363 | Some path -> path
360364 | None ->
365+ let path = location |> Option.defaultValue " <null>"
361366 #if DEBUG
362367 Debug.Print( sprintf """ FSharpEnvironment.BinFolderOfDefaultFSharpCompiler (Some '%s ') returned None Location
363368 customized incorrectly: algorithm here: https://github.com/dotnet/fsharp/blob/03f3f1c35f82af26593d025dabca57a6ef3ea9a1/src/utils/CompilerLocationUtils.fs#L171"""
364- location )
369+ path )
365370 #endif
366371 // Use the location of this dll
367- location
372+ path
373+
374+ // Fallback to ambient FSharp.CompilerService.dll
375+ let getFSharpCompilerLocation () = Path.Combine( getFSharpCompilerLocationWithDefaultFromType( typeof< TypeInThisAssembly>));
376+
377+ // Fallback to ambient FSharp.Core.dll
378+ let getDefaultFSharpCoreLocation () = Path.Combine( getFSharpCompilerLocationWithDefaultFromType( typeof< Unit>), getFSharpCoreLibraryName + " .dll" )
368379
369- let getDefaultFSharpCoreLocation () = Path.Combine ( getFSharpCompilerLocation (), getFSharpCoreLibraryName + " . dll" )
370- let getDefaultFsiLibraryLocation () = Path.Combine( getFSharpCompilerLocation(), fsiLibraryName + " .dll" )
380+ // Must be alongside the location of FSharp.CompilerService. dll
381+ let getDefaultFsiLibraryLocation () = Path.Combine( Path.GetDirectoryName ( getFSharpCompilerLocation() ), fsiLibraryName + " .dll" )
371382
372383 // Path to the directory containing the fsharp compilers
373- let fsharpCompilerPath = Path.Combine( Path.GetDirectoryName( typeof < TypeInThisAssembly >. GetTypeInfo () .Assembly.Location ), " Tools" )
384+ let fsharpCompilerPath = Path.Combine( Path.GetDirectoryName( getFSharpCompilerLocation () ), " Tools" )
374385
375386 let isWindows = RuntimeInformation.IsOSPlatform( OSPlatform.Windows)
376387
0 commit comments