|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.IO; |
| 4 | +using System.Linq; |
| 5 | + |
| 6 | +using Mono.Cecil; |
| 7 | + |
| 8 | +public class ConjureXamarinAndroidCecil |
| 9 | +{ |
| 10 | + const string BaseNameReplacement = "Xamarin.Android.Cecil"; |
| 11 | + const string CecilAssemblyName = BaseNameReplacement; |
| 12 | + const string CecilMdbAssemblyName = BaseNameReplacement + ".Mdb"; |
| 13 | + |
| 14 | + static readonly List<string> internalsVisibleTo = new List<string> { |
| 15 | + "Xamarin.Android.Cecil.Pdb, PublicKey=0024000004800000940000000602000000240000525341310004000011000000438ac2a5acfbf16cbd2b2b47a62762f273df9cb2795ceccdf77d10bf508e69e7a362ea7a45455bbf3ac955e1f2e2814f144e5d817efc4c6502cc012df310783348304e3ae38573c6d658c234025821fda87a0be8a0d504df564e2c93b2b878925f42503e9d54dfef9f9586d9e6f38a305769587b1de01f6c0410328b2c9733db", |
| 16 | + "Xamarin.Android.Cecil.Mdb, PublicKey=0024000004800000940000000602000000240000525341310004000011000000438ac2a5acfbf16cbd2b2b47a62762f273df9cb2795ceccdf77d10bf508e69e7a362ea7a45455bbf3ac955e1f2e2814f144e5d817efc4c6502cc012df310783348304e3ae38573c6d658c234025821fda87a0be8a0d504df564e2c93b2b878925f42503e9d54dfef9f9586d9e6f38a305769587b1de01f6c0410328b2c9733db" |
| 17 | + }; |
| 18 | + |
| 19 | + public static int Main (string[] args) |
| 20 | + { |
| 21 | + if (args.Length < 2) { |
| 22 | + Console.WriteLine ("Usage: <input directory> <output directory>"); |
| 23 | + Console.WriteLine (" <input directory> must have Mono.Cecil.dll and Mono.Cecil.Mdb.dll assemblies"); |
| 24 | + return 1; |
| 25 | + } |
| 26 | + |
| 27 | + string inputDir = args [0]; |
| 28 | + string inputFilePath = Path.Combine (inputDir, "Mono.Cecil.dll"); |
| 29 | + string outputDirPath = args [1]; |
| 30 | + |
| 31 | + var resolver = new DefaultAssemblyResolver (); |
| 32 | + resolver.AddSearchDirectory (Path.GetDirectoryName (inputFilePath)); |
| 33 | + var rp = new ReaderParameters () { |
| 34 | + AssemblyResolver = resolver, |
| 35 | + ReadSymbols = true |
| 36 | + }; |
| 37 | + var monoCecil = AssemblyDefinition.ReadAssembly (inputFilePath, rp); |
| 38 | + monoCecil.Name.Name = CecilAssemblyName; |
| 39 | + |
| 40 | + var ivtCtor = monoCecil.MainModule.ImportReference (typeof (System.Runtime.CompilerServices.InternalsVisibleToAttribute).GetConstructor (new []{typeof(string)})); |
| 41 | + foreach (string ivtParam in internalsVisibleTo) { |
| 42 | + var ca = new CustomAttribute (ivtCtor); |
| 43 | + ca.ConstructorArguments.Add (new CustomAttributeArgument (monoCecil.MainModule.TypeSystem.String, ivtParam)); |
| 44 | + monoCecil.CustomAttributes.Add (ca); |
| 45 | + } |
| 46 | + |
| 47 | + var wp = new WriterParameters { |
| 48 | + WriteSymbols = true |
| 49 | + }; |
| 50 | + |
| 51 | + monoCecil.Write (Path.Combine (outputDirPath, $"{CecilAssemblyName}.dll"), wp); |
| 52 | + |
| 53 | + inputFilePath = Path.Combine (inputDir, "Mono.Cecil.Mdb.dll"); |
| 54 | + var monoCecilMdb = AssemblyDefinition.ReadAssembly (inputFilePath, rp); |
| 55 | + monoCecilMdb.Name.Name = CecilMdbAssemblyName; |
| 56 | + |
| 57 | + AssemblyNameReference monoCecilRef = monoCecilMdb.MainModule.AssemblyReferences.Single (r => String.Compare ("Mono.Cecil", r.Name, StringComparison.Ordinal) == 0); |
| 58 | + monoCecilRef.Name = CecilAssemblyName; |
| 59 | + monoCecilMdb.Write (Path.Combine (outputDirPath, $"{CecilMdbAssemblyName}.dll"), wp); |
| 60 | + |
| 61 | + return 0; |
| 62 | + } |
| 63 | +} |
0 commit comments