Example #1
0
        /// <summary>
        ///     Runs C# project compilation and fills <see cref="ProjectCompilation">ProjectCompilation</see>
        ///     and <see cref="CompiledAssembly">CompiledAssembly</see>.
        /// </summary>
        /// <param name="sandbox"></param>
        /// <param name="dllFilename"></param>
        /// <returns></returns>
        public EmitResult CompileCSharpProject(AssemblySandbox sandbox, string dllFilename)
        {
            // must be public !!!!!!!!!!
            ProjectCompilation = _cSharpProject.GetCompilationAsync().Result;
            ProjectCompilation =
                ProjectCompilation.WithOptions(new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
            ProjectCompilation = ProjectCompilation.WithReferences(_cSharpProject.MetadataReferences);
            foreach (var i in ProjectCompilation.References)
            {
                Console.WriteLine("   linked with {0}", i.Display);
            }

            var tmp = sandbox.EmitCompiledAssembly(ProjectCompilation, out var result, dllFilename);

            CompiledAssembly = tmp?.WrappedAssembly;
            return(result);
        }