diff --git a/src/Compiler/Infer/ModelCompiler.cs b/src/Compiler/Infer/ModelCompiler.cs
index 91bab2b4..4cd632a1 100644
--- a/src/Compiler/Infer/ModelCompiler.cs
+++ b/src/Compiler/Infer/ModelCompiler.cs
@@ -156,6 +156,13 @@ public IAlgorithm Algorithm
///
public CompilerChoice CompilerChoice { get; set; } = CompilerChoice.Auto;
+#if ROSLYN
+ ///
+ /// Resolves reference to assembly for Roslyn.
+ ///
+ public Func ReferenceResolver;
+#endif
+
private bool useParallelForLoops = false;
///
@@ -822,7 +829,8 @@ internal T CompileWithoutParams(List itds)
includeDebugInformation = IncludeDebugInformation,
optimizeCode = !IncludeDebugInformation, // tie these together for now
showProgress = ShowProgress,
- compilerChoice = CompilerChoice
+ compilerChoice = CompilerChoice,
+ ReferenceResolver = ReferenceResolver,
};
CompilerResults cr = cc.WriteAndCompile(itds);
// Examine the compilation results and stop if errors
diff --git a/src/Compiler/TransformFramework/CodeTransformer.cs b/src/Compiler/TransformFramework/CodeTransformer.cs
index dd49fef8..f22af7bb 100644
--- a/src/Compiler/TransformFramework/CodeTransformer.cs
+++ b/src/Compiler/TransformFramework/CodeTransformer.cs
@@ -146,6 +146,12 @@ public class CodeCompiler
///
public CompilerChoice compilerChoice = CompilerChoice.Auto;
+#if ROSLYN
+ ///
+ /// Resolves reference for Roslyn
+ ///
+ public Func ReferenceResolver;
+#endif
public List WriteSource(List typeDeclarations, IList filenames, out ICollection referencedAssemblies)
{
Stopwatch watch = null;
@@ -449,7 +455,24 @@ private CompilerResults CompileWithRoslyn(List filenames, List s
{
try
{
- references.Add(MetadataReference.CreateFromFile(assembly.Location));
+ MetadataReference metadataReference;
+ if (assembly.Location == "" && ReferenceResolver != null)
+ {
+ var bytes = ReferenceResolver(assembly);
+ if (bytes is null)
+ {
+ // do nothing - this assembly does not have a location e.g. it is in memory
+ continue;
+ }
+
+ metadataReference = MetadataReference.CreateFromImage(bytes);
+ }
+ else
+ {
+ metadataReference = MetadataReference.CreateFromFile(assembly.Location);
+ }
+
+ references.Add(metadataReference);
}
catch (NotSupportedException)
{