是否可以在 Windows 上使用 Visual Studio 调试使用 Mono/XBuild 编译的程序集? [英] Is it possible to debug assemblies compiled with Mono / XBuild with Visual Studio on Windows?

查看:16
本文介绍了是否可以在 Windows 上使用 Visual Studio 调试使用 Mono/XBuild 编译的程序集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 XBuild 为 Mono 编译 Visual Studio 解决方案.这会生成程序集 + mdb 文件.是否有可能在 Windows 上使用 Visual Studio 调试此程序集?使用附加到进程"时,我无法调试,因为显示未加载符号的错误.

I'm using XBuild to compile Visual Studio solutions for Mono. This generates the assembly + mdb file. Is there a possibility to debug this assembly with Visual Studio on Windows? When using "Attach to process" i can't debug because an error is shown that the symbols aren't loaded.

我尝试通过 Mono.Cecil(AssemblyDefinition、MdbReaderProvider、PdbWriterProvider)为该程序集生成 pdb 文件,并通过 Debug/Windows/Modules 和Load Symbol From/Symbol Path"手动加载它,它实际上加载了符号(如图所示在模块"窗口中),但这也不能启用调试.

I tried generating the pdb file for this assembly via Mono.Cecil (AssemblyDefinition, MdbReaderProvider, PdbWriterProvider) and loading it manually via Debug / Windows / Modules and "Load Symbol From / Symbol Path", which actually loads the symbols (shown in the Modules windows) but that doesn't enable debugging either.

推荐答案

在比较 VS2012 构建和 XBuild 构建之间的程序集定义时,我注意到 XBuild 没有生成 DebuggableAttribute.如果缺少此属性,则无法使用 Visual Studio 2012 进行调试,即使您手动加载符号也是如此.使用 VS2012 调试 Mono/XBuild 编译的程序集需要以下步骤:

When comparing assembly definitions between VS2012 builds and XBuild builds, i noticed that XBuild is not generating the DebuggableAttribute. If this attribute is missing, debugging with Visual Studio 2012 isn't possible, even if you load the symbols manually. Following steps are needed to debug assemblies compiled with Mono / XBuild with VS2012:

  1. 使用 XBuild 编译解决方案
  2. 对每个要调试的程序集使用 Mono.Cecil 以生成 pdb 文件并注入 DebuggableAttribute(参见下面的代码)
  3. 从 XBuild 编译程序开始
  4. 使用 VS2012 中的Debug/Attach to process..."来调试正在运行的程序

生成pdb和注入DebuggableAttribute的代码:

Code for generating pdb and injecting DebuggableAttribute:

string assemblyPath = @"HelloWorld.exe";

var assemblyDefinition = AssemblyDefinition.ReadAssembly(assemblyPath,
    new ReaderParameters() { SymbolReaderProvider = new MdbReaderProvider(), ReadSymbols = true});

CustomAttribute debuggableAttribute = newCustomAttribute(
assemblyDefinition.MainModule.Import(
    typeof(DebuggableAttribute).GetConstructor(new[] { typeof(bool), typeof(bool) })));

debuggableAttribute.ConstructorArguments.Add(new CustomAttributeArgument(
    assemblyDefinition.MainModule.Import(typeof(bool)), true));

debuggableAttribute.ConstructorArguments.Add(new CustomAttributeArgument(
    assemblyDefinition.MainModule.Import(typeof(bool)), true));

assemblyDefinition.CustomAttributes.Add(debuggableAttribute);

assemblyDefinition.Write(assemblyPath,
    new WriterParameters() { SymbolWriterProvider = new PdbWriterProvider(), WriteSymbols = true});

这篇关于是否可以在 Windows 上使用 Visual Studio 调试使用 Mono/XBuild 编译的程序集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆