Skip to content

Commit 98b1f07

Browse files
committed
Merge pull request #260 from dsyme/docfix-2
Documentation about referencing and/or including FSharp.Core.dll
2 parents f96e31b + 2d46a7a commit 98b1f07

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

docs/content/corelib.fsx

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
(*** hide ***)
2+
#I "../../bin/v4.5/"
3+
(**
4+
Compiler Services: Notes on FSharp.Core.dll
5+
=================================================
6+
7+
Shipping an FSharp.Core with your application
8+
---------------------------------------------
9+
10+
11+
When building applications or plug-in components which use ``FSharp.Compiler.Service.dll``, you will normally need
12+
to ship a copy of ``FSharp.Core.dll`` as part of your application.
13+
14+
For example, if you build a HostedCompiler.exe, you will normally place an ``FSharp.Core.dll`` (say 4.3.1.0) alongside
15+
your HostedCompiler.exe.
16+
17+
Sometimes you will also need to include an ``FSharp.Core.optdata`` and ``FSharp.Core.sigdata``, see below.
18+
19+
Binding redirects for your application
20+
--------------------------------------
21+
22+
The ``FSharp.Compiler.Service.dll`` component depends on FSharp.Core 4.3.0.0. Normally your application will target
23+
a later version of FSharp.Core. This means you will also need a binding-redirect file to make sure
24+
that FSharp.Core 4.3.0.0 forwards to which ever final version of ``FSharp.Core.dll`` your application runs correctly.
25+
Binding redirect files are normally generated automatically by build tooling. If not, you can use a
26+
27+
``
28+
<?xml version="1.0" encoding="utf-8" ?>
29+
<configuration>
30+
<runtime>
31+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
32+
<dependentAssembly>
33+
<assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
34+
<bindingRedirect oldVersion="2.0.0.0-4.3.0.0" newVersion="4.3.1.0"/>
35+
</dependentAssembly>
36+
</assemblyBinding>
37+
</runtime>
38+
</configuration>
39+
``
40+
41+
Which FSharp.Core and .NET Framework gets referenced in compilation?
42+
--------------------------------------
43+
44+
The FSharp.Compiler.Service component can be used to do more or less any sort of F# compilation.
45+
In particular you can reference an explicit FSharp.Core and/or framework
46+
assemblies in the command line arguments (different to the FSharp.Core and a .NET Framework being used to run your tool).
47+
48+
To target a specific FSharp.Core and/or .NET Framework assemblies, use the ``--noframework`` argument
49+
and the appropriate command-line arguments:
50+
51+
let errors2, exitCode2 =
52+
scs.Compile([| "fsc.exe"; "--noframework"; "-r"; @"C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\4.3.1.0\FSharp.Core.dll"; "-r"; @"C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll"; "-o"; fn3; "-a"; fn2 |])
53+
54+
55+
56+
You will need to determine the location of these assemblies. The easiest ways to locate these DLLs in a cross-platform way and
57+
convert them to command-line arguments is to [crack an F# project file](http://fsharp.github.io/FSharp.Compiler.Service/project.html).
58+
Alternatively you can compute SDK paths yourself, and some helpers to do this are in [the tests for FSharp.Compiler.Service.dll](https://github.com/fsharp/FSharp.Compiler.Service/blob/8a943dd3b545648690cb3bed652a469bdb6dd869/tests/service/Common.fs#L54).
59+
60+
61+
Do I need to include ``FSharp.Core.optdata`` and ``FSharp.Core.sigdata``?
62+
--------------------------------------
63+
64+
If your compilation arguments explicitly reference an ``FSharp.Core.dll`` from an SDK location, then ``FSharp.Core.sigdata`` and ``FSharp.Core.optdata`` should be alongside the DLL
65+
(if these files are not installed, then that's a bug in the F# SDK installation). If your compilation
66+
arguments are always making an explicit reference, then you should _not_ include ``FSharp.Core.optdata`` and ``FSharp.Core.sigdata`` as part of your application.
67+
68+
69+
If you do _not_ explicitly reference an ``FSharp.Core.dll`` from an SDK location, then an implicit reference will be made
70+
to whichever FSharp.Core.dll your tool is running. This means your tool will almost certainly implicitly reference the FSharp.Core.dll
71+
that is part of your application. In this case, you may either get an error that ``FSharp.Core.optdata`` and ``FSharp.Core.sigdata`` are not
72+
found alongside FSharp.Core.dll. If you want to implicitly reference the ``FSharp.Core.dll`` you are including in your application,
73+
then also add ``FSharp.Core.sigdata`` and ``FSharp.Core.optdata`` as two additional files to your application. When using CompileToDynamicAssembly, this problem
74+
can also manifest itself as [a stack overflow during assembly resolution](https://github.com/fsharp/FSharp.Compiler.Service/issues/258).
75+
76+
Tools that dynamically compile and execute code (e.g. a ``HostedExecution.exe``) normally make an implicit reference to FSharp.Core.dll.
77+
78+
Summary
79+
-------
80+
81+
In this design note we've discussed three things
82+
83+
- which FSharp.Core.dll is used to run your compilation tool
84+
- how to configure binding redirects for the FSharp.Core.dll used to run your compilation tool
85+
- which FSharp.Core.dll and/or framework assemblies are referenced during the checking and compilations performed by your tool.
86+
87+
*)

docs/tools/templates/template.cshtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
<li class="nav-header">Design Notes</li>
7171
<li><a href="@Root/queue.html">The FSharpChecker operations queue</a></li>
7272
<li><a href="@Root/caches.html">The FSharpChecker caches</a></li>
73+
<li><a href="@Root/corelib.html">Notes on FSharp.Core.dll</a></li>
7374

7475
<li class="nav-header">Documentation</li>
7576
<li><a href="@Root/reference/index.html">API Reference</a> (Preliminary)

0 commit comments

Comments
 (0)