When building applications or plug-in components which use FSharp.Compiler.Service.dll, you will normally also include a copy of FSharp.Core.dll as part of your application.
For example, if you build a
HostedCompiler.exe, you will normally place an FSharp.Core.dll (say 126.96.36.199) alongside
The FSharp.Compiler.Service.dll component depends on FSharp.Core 188.8.131.52. Normally your application will target
a later version of FSharp.Core, and you may need a binding redirect to ensure
that other versions of FSharp.Core forward to the final version of FSharp.Core.dll your application uses.
Binding redirect files are normally generated automatically by build tools. If not, you can use one like this
(if your tool is called
HostedCompiler.exe, the binding redirect file is called
Some other dependencies may also need to be reconciled and forwarded.
<?xml version="1.0" encoding="utf-8" ?> <configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/> <bindingRedirect oldVersion="184.108.40.206-220.127.116.11" newVersion="18.104.22.168"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="22.214.171.124-126.96.36.199" newVersion="188.8.131.52" /> </dependentAssembly> </assemblyBinding> </runtime> </configuration>
The FSharp.Compiler.Service component can be used to do more or less any sort of F# compilation. In particular you can reference an explicit FSharp.Core and/or framework assemblies in the command line arguments (different to the FSharp.Core and a .NET Framework being used to run your tool).
To target a specific FSharp.Core and/or .NET Framework assemblies, use the
and the appropriate command-line arguments:
[<Literal>] let fsharpCorePath = @"C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\184.108.40.206\FSharp.Core.dll" let errors2, exitCode2 = scs.Compile( [| "fsc.exe"; "--noframework"; "-r"; fsharpCorePath; "-r"; @"C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll"; "-o"; fn3; "-a"; fn2 |])
You will need to determine the location of these assemblies. The easiest way to locate these DLLs in a cross-platform way and convert them to command-line arguments is to crack an F# project file. Alternatively you can compute SDK paths yourself, and some helpers to do this are in the tests for FSharp.Compiler.Service.dll.
If you do not explicitly reference an FSharp.Core.dll from an SDK location, or if you are processing a script
GetCheckOptionsFromScriptRoot, then an implicit reference to FSharp.Core will be made
by the following choice:
The version of FSharp.Core.dll statically referenced by the host assembly returned by
If there is no static reference to FSharp.Core in the host assembly, then
No, unless you are doing something with very old FSharp.Core.dll.
In this design note we have discussed three things: