Skip to content

Instantly share code, notes, and snippets.

@aaron-comyn
Last active June 8, 2018 11:24
Show Gist options
  • Save aaron-comyn/e178636def80d898f61ce4eeead21b3b to your computer and use it in GitHub Desktop.
Save aaron-comyn/e178636def80d898f61ce4eeead21b3b to your computer and use it in GitHub Desktop.
Compilation error in FSharp Interactive (FSI), when using Roslyn
(*
Compilation error in FSI
------------------------
The following source compiles as expected and works in a DotNetCore application.
Run in FSI it will complain about missing types between the Roslyn libraries.
Tested on the last years worth of Roslyn releases, VS2017, F# Interactive version 10.1.0 for F# 4.1
The issue has been confirmed by using the published libraries from a working F# console application.
*)
#I @"../../../packages"
#r "NETStandard.Library.NETFramework/build/net461/lib/netstandard.dll"
#r "Microsoft.CodeAnalysis.CSharp/lib/netstandard1.3/Microsoft.CodeAnalysis.CSharp.dll" // v2.8.2
#r "Microsoft.CodeAnalysis.Common/lib/netstandard1.3/Microsoft.CodeAnalysis.dll" // v2.8.2
#r "System.Text.Encoding/ref/netstandard1.3/System.Text.Encoding.dll"
#r "System.Collections.Immutable/lib/netstandard2.0/System.Collections.Immutable.dll"
// Basic C# class to compile
let csharp = """
using System;
namespace HelloWorld
{
class Hello
{
static void Main()
{
Console.WriteLine("Hello World!");
// Keep the console window open in debug mode.
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
}
}"""
open Microsoft.CodeAnalysis.CSharp.Syntax
open Microsoft.CodeAnalysis.CSharp
open Microsoft.CodeAnalysis
let syntaxTree = CSharpSyntaxTree.ParseText(csharp)
// In a .NetCore console appplication this will compile an assembly, in FSI it errors due to missing types in Microsoft.CodeAnalysis.dll
let compilation =
CSharpCompilation.Create(
"assemblyName",
[ syntaxTree ],
[ MetadataReference.CreateFromFile(typeof<obj>.Assembly.Location) ],
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment