Mono Cecil错误生成PDB

时间:2013-11-04 14:53:36

标签: c# pdb-files mono.cecil

下面的代码允许我更改方法体并保存组件。

        // Recreate PDB
        var assemblyResolver = new DefaultAssemblyResolver();
        var assemblyLocation = Path.GetDirectoryName(pathBin);
        assemblyResolver.AddSearchDirectory(assemblyLocation);
        /*if (!string.IsNullOrEmpty(HintPath))
        {
            assemblyResolver.AddSearchDirectory(HintPath);
        }*/
        var silverlightAssemblyPath = Environment.ExpandEnvironmentVariables(@"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\");
        assemblyResolver.AddSearchDirectory(silverlightAssemblyPath);
        var readerParameters = new ReaderParameters { AssemblyResolver = assemblyResolver };
        var writerParameters = new WriterParameters();
        var pdbName = Path.ChangeExtension(pathBin, "pdb");
        if (createPDB && File.Exists(pdbName))
        {
            var symbolReaderProvider = new PdbReaderProvider();
            readerParameters.SymbolReaderProvider = symbolReaderProvider;
            readerParameters.ReadSymbols = true;
            writerParameters.WriteSymbols = true;
        }
        //Gets the AssemblyDefinition of "MyLibrary"
        AssemblyDefinition assembly = AssemblyDefinition.ReadAssembly(pathBin, readerParameters);
        System.IO.File.Delete(pathBin.Replace(".dll", ".back"));
        assembly.Write(pathBin.Replace(".dll", ".back"));

        if (assembly.Modules.SelectMany(m => m.Types.SelectMany(t => t.Methods.Select(meth => new MethodDefinitionEx(assembly, t, meth))))
            .Where(exp)
            .Any())
        {
            //Save
            if (createPDB)
                assembly.Write(pathBin, writerParameters);
            else
                assembly.Write(pathBin);
            return true;
        }
        return false;

但是当我要求cecil创建符号文件(pdb)时,创建的文件与原始文件完全不同,我无法调试生成的程序集。

我在google上找到了这个引用......但是对我来说没什么用。

  • johnhmarks.wordpress.com/2011/01/19/getting-mono-cecil-to-rewrite-pdb-files-to-enable-debugging
  • groups.google.com/forum /#!话题/单塞西尔/ s0Dc3GSgsHY
  • github.com/jbevain/cecil/issues/4

任何人

0 个答案:

没有答案