Hi JB,
Apparently my initial, patchy solution DID work after all!
I had an internal AssemblyResolver event handler that intervened
caused an error that I though had to do with my clunky cecil patcher.
Anyways, for posterity here's the full f# code that patches the
assembly:
open Mono.Cecil;
open Mono.Cecil.Pdb;
open System.IO;
open System.Text.RegularExpressions;
let patchAssembly (targetAsm : string) (targetPatchedAsm : string)
(targetPatchedAsmPdb : string) (re : Regex) (replace : string) =
let ar = new DefaultAssemblyResolver()
ar.AddSearchDirectory(@"c:\Windows\Microsoft.NET
\Framework64\v4.0.30319")
let rp = new ReaderParameters(AssemblyResolver = ar,
ReadSymbols = true,
ReadingMode = ReadingMode.Immediate,
SymbolReaderProvider =new
PdbReaderProvider())
let ad = AssemblyDefinition.ReadAssembly(targetAsm, rp)
let md = ad.Modules.[0]
md.AssemblyReferences |> Seq.filter (fun r -> re.IsMatch(r.Name)) |>
Seq.iter (fun r -> r.Name <- replace)
//let newPdb = new FileStream(targetPatchedAsmPdb, FileMode.Create)
let wp = new WriterParameters(WriteSymbols = true,
SymbolWriterProvider = new
PdbWriterProvider())
ad.Write(targetPatchedAsm, wp)
ignore
[<EntryPoint>]
let main (args : string[]) =
let targetAsm = args.[0]
let targetPatchedAsm = args.[1]
let targetPatchedAsmPdb = args.[2]
let re = new Regex(args.[3])
let replace = args.[4]
patchAssembly targetAsm targetPatchedAsm targetPatchedAsmPdb re
replace
1
This will forecully replace the assembly reference name, while still
re-writing the PDB is there's any.
I wanted to take this opportunity to thank you for writing such a
wonderful, well implemented library.
On Jun 1, 11:31 pm, Jb Evain <[email protected]> wrote:
> On Tue, Jun 1, 2010 at 10:24 PM, damageboy <[email protected]> wrote:
> > So just to make sure (That I'm not missing out on something)...
>
> > I find to find the TypeReference on every Type and Nested Type by
> > looking into their:
> > * Generic Arguments
> > * Fields
> > * Properties
> > * Method Declarations (Return Values, Generic Arguments, Parameters)
> > * Method Bodies (using ILVisitor or something like that)
>
> * Events
> * CustomAttributes arguments
>
> > (Or maybe I should just ildasm / sed / ilasm ;)
>
> Actually, this may be bit easier. But you depend on how ildasm
> represents dups in the assembly ref table.
>
> --
> Jb Evain <[email protected]>
--
--
mono-cecil