Пример #1
0
        private static FileDescriptor Compile(List <FileSystemDescriptor> files)
        {
            FileDescriptor outputAssembly = new FileDescriptor(Application.CacheDirectory, MixinAssemblyFileName);

            SE.Forge.SharpCompiler.Compiler compiler = new SE.Forge.SharpCompiler.Compiler();
            compiler.Options.OutputType = Systems.OutputAssemblyType.Library;
            #if DEBUG
            compiler.Options.Debug = true;
            #endif
            compiler.Options.TargetFile = outputAssembly;

            foreach (FileDescriptor file in files)
            {
                compiler.Options.Sources.Add(file.GetAbsolutePath());
            }

            foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                if (!assembly.IsDynamic)
                {
                    compiler.Options.Dependencies.Add(assembly.Location);
                }
            }

            compiler.Execute();
            return(outputAssembly);
        }
Пример #2
0
        FileDescriptor Compile(List <FileSystemDescriptor> files)
        {
            FileDescriptor outputAssembly = new FileDescriptor(Application.CacheDirectory, PluginAssemblyFileName, path.Name);

            SE.Forge.SharpCompiler.Compiler compiler = new SE.Forge.SharpCompiler.Compiler();
            compiler.Options.OutputType = Systems.OutputAssemblyType.Library;
            #if DEBUG
            compiler.Options.Debug = true;
            #endif
            compiler.Options.TargetFile = outputAssembly;

            foreach (FileDescriptor file in files)
            {
                compiler.Options.Sources.Add(file.GetAbsolutePath());
            }

            compiler.Options.Dependencies.Add("System.dll");
            compiler.Options.Dependencies.Add("System.Core.dll");
            compiler.Options.Dependencies.Add("Microsoft.CSharp.dll");

            List <KeyValuePair <int, string> > usings = new List <KeyValuePair <int, string> >();
            foreach (FileDescriptor file in files)
            {
                usings.Clear();
                SharpAnalyzer.CodeParser.GetUsingDirectives(file.GetText(Encoding.UTF8), usings);
                foreach (string dependency in usings.Select(x => x.Value))
                {
                    if (dependency != "System")
                    {
                        List <FileDescriptor> assemblies; if (SharpAnalyzer.AssemblyResolver.TryGetAssemblies(dependency.Fnv32(), out assemblies))
                        {
                            foreach (FileDescriptor assembly in assemblies)
                            {
                                if (!compiler.Options.Dependencies.Contains(assembly.GetAbsolutePath()))
                                {
                                    compiler.Options.Dependencies.Add(assembly.GetAbsolutePath());
                                }
                            }
                        }
                    }
                }
            }

            foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                if (!assembly.IsDynamic && !assembly.GlobalAssemblyCache)
                {
                    if (!compiler.Options.Dependencies.Contains(assembly.Location))
                    {
                        compiler.Options.Dependencies.Add(assembly.Location);
                    }
                }
            }

            compiler.Execute();
            return(outputAssembly);
        }