public static void Compile(Type type, out MethodDefinition methdoDefinition) { methdoDefinition = null; var assembly = type.Assembly.Location; var refs = from an in type.Assembly.GetReferencedAssemblies() let a = System.Reflection.Assembly.Load(an) select a.Location; var xamlc = new XamlCTask { Assembly = assembly, ReferencePath = refs.ToArray(), KeepXamlResources = true, OptimizeIL = true, DebugSymbols = false, ValidateOnly = true, Type = type.FullName, BuildEngine = new MSBuild.UnitTests.DummyBuildEngine() }; if (xamlc.Execute(out IList <Exception> exceptions) || exceptions == null || !exceptions.Any()) { methdoDefinition = xamlc.InitCompForType; return; } if (exceptions.Count > 1) { throw new AggregateException(exceptions); } throw exceptions[0]; }
public static void Main(string[] args) { bool help = false; int verbosity = 1; bool keep = false; bool optimize = false; bool decompile = false; string paths = null; string refs = null; List <string> extra = null; var p = new OptionSet { { "h|?|help", "Print this help message", v => help = true }, { "v=|verbosity=", "0 is quiet, 1 is normal, 2 is verbose", v => verbosity = Int32.Parse(v) }, { "o|optimize", "Optimize generated IL", v => optimize = true }, { "keep", "do not strip compiled embedded xaml", v => keep = true }, { "p=|paths=|dependencypaths=", "look for dependencies in (comma separated) list of paths", v => paths = v }, { "r=", "referencepath", v => refs = v }, { "d|decompile", v => decompile = true } }; if (help || args.Length < 1) { ShowHelp(p); Environment.Exit(0); } try { extra = p.Parse(args); } catch (OptionException) { Console.WriteLine("Type `xamlc --help' for more information."); return; } if (extra.Count == 0) { if (verbosity > 0) { Console.WriteLine("assembly missing"); ShowHelp(p); } Environment.Exit(0); } var assembly = extra[0]; var xamlc = new XamlCTask { Assembly = assembly, Verbosity = verbosity, KeepXamlResources = keep, OptimizeIL = optimize, DependencyPaths = paths, ReferencePath = refs, OutputGeneratedILAsCode = decompile, }; xamlc.Execute(null); }
public static void Compile(Type type, out MethodDefinition methdoDefinition) { methdoDefinition = null; var assembly = type.Assembly.Location; var refs = from an in type.Assembly.GetReferencedAssemblies() let a = System.Reflection.Assembly.Load(an) select a.Location; var xamlc = new XamlCTask { Assembly = assembly, ReferencePath = string.Join(";", refs), KeepXamlResources = true, OptimizeIL = true, DebugSymbols = false, ReadOnly = true, Type = type.FullName }; IList <Exception> exceptions; if (xamlc.Execute(out exceptions) || exceptions == null || !exceptions.Any()) { methdoDefinition = xamlc.InitCompForType; return; } if (exceptions.Count > 1) { throw new AggregateException(exceptions); } throw exceptions[0]; }
public static void Compile(Type type) { var assembly = type.Assembly.Location; var refs = from an in type.Assembly.GetReferencedAssemblies() let a = System.Reflection.Assembly.Load(an) select a.Location; var xamlc = new XamlCTask { Assembly = assembly, ReferencePath = string.Join(";", refs), KeepXamlResources = true, Type = type.FullName }; var exceptions = new List <Exception>(); if (!xamlc.Execute(exceptions) && exceptions.Any()) { throw exceptions [0]; } }
public void Modify(IEnumerable <UnityEditor.Compilation.Assembly> lockedAssemblies, IEnumerable <string> sources = null) { var modifiers = new List <ILModifier>(); EditorApplication.LockReloadAssemblies(); try { using (var resolver = new Resolver()) { var xamarin = new ILXamarin(resolver); foreach (var assembly in lockedAssemblies) { var definition = resolver.Add(assembly.outputPath, true); if (definition != null) { modifiers.Add(new ILModifier(assembly, definition)); } } var engine = new Build.BuildEngine(); var logger = new Build.Logger(); logger.Verbosity = Settings.Verbosity; logger.Initialize(engine); while (modifiers.Count > 0) { var modifier = modifiers.Last(); try { foreach (var reference in modifier.compilation.allReferences) { resolver.Add(reference, false); } var modified = modifier.Modify(xamarin, _types, sources); if (modified) { modifier.Write(); } if (modified) { resolver.DisposeAssembly(modifier.compilation.outputPath, modifier.definition); var task = new XamlCTask(); task.BuildEngine = engine; task.Assembly = modifier.compilation.outputPath; task.DebugSymbols = Settings.DebugSymbols.value; task.DebugType = "portable"; task.OptimizeIL = Settings.OptimizeIL.value; task.CompileByDefault = true; task.DefaultAssemblyResolver = resolver; engine.ProjectFileOfTaskNode = task.Assembly; task.Execute(); } } catch (Exception exception) { Debug.LogException(exception); } finally { modifiers.RemoveAt(modifiers.Count - 1); modifier.Dispose(); } } } } finally { EditorApplication.UnlockReloadAssemblies(); foreach (var modifier in modifiers) { modifier.Dispose(); } } }