public static IEnumerable <Assembly> GetReferencedAssemblies(CompilationUnitSyntax executingScriptCompilationSource, string scriptFolder)
        {
            var assms = new List <Assembly>();

            foreach (var refDirective in executingScriptCompilationSource.GetReferenceDirectives())
            {
                var path = FileUtilities.BuildFullPath(scriptFolder, refDirective.File.ValueText);
                assms.Add(Assembly.ReflectionOnlyLoadFrom(path));
            }
            return(assms);
        }
        public static Tuple <CompilationUnitSyntax, List <Assembly> > ExtractReferenceDirectives(CompilationUnitSyntax compilationUnit, string baseFolder)
        {
            var assms         = new List <Assembly>();
            var refDirectives = compilationUnit.GetReferenceDirectives();

            foreach (var refDirective in refDirectives)
            {
                var path = FileUtilities.BuildFullPath(baseFolder, refDirective.File.ValueText);
                assms.Add(Assembly.ReflectionOnlyLoadFrom(path));
                compilationUnit = compilationUnit.RemoveNode(refDirective, SyntaxRemoveOptions.KeepNoTrivia);
            }
            return(new Tuple <CompilationUnitSyntax, List <Assembly> >(compilationUnit, assms));
        }