示例#1
0
文件: Compiler.cs 项目: chartly/flood
        public void CompileApi(string outputPath)
        {
            using (var emptyAssemblyPaths = new TemporaryAssemblyPaths())
            using (var apiAssemblyPaths = new TemporaryAssemblyPaths())
            {
                CreateEmptyAssembly(emptyAssemblyPaths.DllPath);

                var weaver = new AssemblyWeaver(emptyAssemblyPaths.DllPath);
                var types = RpcTypes.Select(t => t.FullName);
                weaver.CopyTypes(destAssemblyPath, types);
                weaver.Write(apiAssemblyPaths.DllPath);

                var references = weaver.GetReferences();

                CompileIntoAssembly(apiAssemblyPaths.DllPath, outputPath, references);
            }
        }
示例#2
0
文件: Compiler.cs 项目: chartly/flood
        private void CompileIntoAssembly(string destPath, string outputPath, HashSet<string> references)
        {
            outputPath = Path.GetFullPath(outputPath);

            using (var generatedAssembly = new TemporaryAssemblyPaths())
            {

                FieldsToProperties(destPath, outputPath);

                CodeDomProvider provider = new CSharpCodeProvider();
                CompilerParameters cp = new CompilerParameters()
                {
                    GenerateExecutable = false,
                    OutputAssembly = generatedAssembly.DllPath,
                    IncludeDebugInformation = true,
                    CompilerOptions = "/unsafe"
                };

                references.Add(outputPath);
                foreach (var @ref in references)
                    cp.ReferencedAssemblies.Add(@ref);

                CompilerResults cr = provider.CompileAssemblyFromFile(cp, GeneratedFiles.ToArray());

                if (cr.Errors.HasErrors)
                {
                    var message = new StringBuilder();
                    message.Append("Error compiling generated files.\n");
                    foreach(var error in cr.Errors)
                        message.AppendFormat("  {0}\n",error.ToString());
                    throw new Exception(message.ToString());
                }

                var weaver = new AssemblyWeaver(outputPath);
                weaver.MergeTypes(generatedAssembly.DllPath, DataObjectsMap);
                weaver.AddAssembly(generatedAssembly.DllPath);
                weaver.Write(outputPath);
            }
        }