下面的代码允许我更改方法体并保存组件。
// 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上找到了这个引用......但是对我来说没什么用。
任何人