public void CompileAndRunTests() { var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(_sourceCodeFile); var compilation = CSharpCompilation.Create ( assemblyName: fileNameWithoutExtension, syntaxTrees: new[] { CSharpSyntaxTree.ParseText(FileWithoutLock.ReadAllText(_sourceCodeFile)) }, references: new [] { MetadataReference.CreateFromFile(typeof(object).Assembly.Location), //mscorlib.dll MetadataReference.CreateFromFile(typeof(Enumerable).Assembly.Location), //System.Core.dll MetadataReference.CreateFromFile(typeof(Uri).Assembly.Location) //System.dll }, options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary) ); var buildedMethod = CompilationHelper.For(compilation) .TryEmit( onSuccess: assembly => assembly .GetTypes() .Single(t => t.Name == fileNameWithoutExtension) .GetMethod(_parameters.StaticMethodToRun), onErrorAction: diagnostic => { var sourceFileName = Path.GetFileName(_sourceCodeFile); if (diagnostic.Severity == DiagnosticSeverity.Error || diagnostic.IsWarningAsError) { var lineSpan = diagnostic.Location.GetMappedLineSpan(); var startLine = lineSpan.StartLinePosition.Line + 1; var color = diagnostic.IsWarningAsError ? Color.Orange : Color.Red; Console.WriteLine($"{sourceFileName} L{startLine} : {diagnostic.Id}: {diagnostic.GetMessage()}", color); } }); RunTests(buildedMethod); }