Project reference resolution using FSharp.Compiler.Service

Robin Neatherway - Wed 29 October 2014 - fsharp, msbuild, .net

Since my last post, I've been working on integrating that approach into the FSharp.Compiler.Service (FCS) project so that it can be used more easily by others. With some help, this is now available in version 0.0.73 from NuGet and has some great documentation with examples. See the 'Cracking a project file' at the bottom of project page, where you can see an interface built right into the InteractiveChecker class that produces ProjectOptions (including fully resolved references and other compiler options) required for intellisense calls. For simpler requirements, the FSharpProjectFileInfo.Parse method returns an object with various members: References, ProjectReferences, OutputFile and more.

If your project doesn't use the rest of FCS and you want to avoid taking such a large dependency, I've made a single-file GitHub repository that can be included using Paket. In this case your paket.dependencies file should contain:

github rneatherway/FSharpProjectFileInfo FSharpProjectFileInfo.fs

and a project file can be processed using:


In this instance you need to make sure you also reference the necessary MSBuild assemblies:

<Reference Include="Microsoft.Build" />
<Reference Include="Microsoft.Build.Engine" />
<Reference Include="Microsoft.Build.Framework" />
<Reference Include="Microsoft.Build.Tasks.v4.0" />
<Reference Include="Microsoft.Build.Utilities.v4.0" />

In order to parse project files using ToolsVersion 12.0 (produced by VS2013), you will need to ensure that you reference Version 12 of these assemblies:

<Reference Include="Microsoft.Build" Version="" />
<Reference Include="Microsoft.Build.Engine" Version="" />
<Reference Include="Microsoft.Build.Framework" Version="" />
<Reference Include="Microsoft.Build.Tasks.v4.0" Version="" />
<Reference Include="Microsoft.Build.Utilities.v4.0" Version="" />