如何断点调试被 .exe 程序调用的 C# 类库?

讨论 未结 8 62
yodhcn yodhcn
yodhcn yodhcn 会员 2022年4月26日 04:17 发表
<p>楼主在尝试开发一个 jellyfin 插件,按照官方文档 <a href="https://github.com/jellyfin/jellyfin-plugin-template" rel="nofollow">https://github.com/jellyfin/jellyfin-plugin-template</a> 配置环境,在调试时 Visual Studio 却提示"当前不会命中断点, 还没有为该文档加载任何符号"。<br> 搞得一头雾水,恳请大佬能帮楼主捋一捋,到底是哪里出了问题。</p> <p>环境:<br> 便携版的 jellyfin 路径在 D:\jellyfin<br> 被调试插件源码路径在 C:\Users\admin\Documents\GitHub\jellyfin-plugin-template<br> jellyfin 插件文件夹路径在 从 C:\Users\admin\AppData\Local\jellyfin\plugins<br> 使用 Visual Studio 2022 调试代码</p> <p>操作步骤:</p> <ol> <li>按照文档的步骤 <a href="https://github.com/jellyfin/jellyfin-plugin-template#6a-set-up-debugging-on-visual-studio" rel="nofollow">https://github.com/jellyfin/jellyfin-plugin-template#6a-set-up-debugging-on-visual-studio</a> 将 D:\jellyfin\jellyfin.exe 设为 "启动项目"<br> 并在 Debug 模式下生成 Jellyfin.Plugin.Template.dll 文件<br> <img alt="" class="embedded_image" loading="lazy" referrerpolicy="no-referrer" rel="noreferrer" src="https://i0.hdslb.com/bfs/album/5c40b26cfb05f9692e78b8750e214f990c51d764.png"></li> <li>将 jellyfin-plugin-template\Jellyfin.Plugin.Template\bin\Debug\net6.0 文件夹下的内容全部复制到 jellyfin 的插件文件夹 C:\Users\admin\AppData\Local\jellyfin\plugins\Template<br> 设置断点<br> 点击 "启动" 开始调试 <img alt="" class="embedded_image" loading="lazy" referrerpolicy="no-referrer" rel="noreferrer" src="https://i0.hdslb.com/bfs/album/584fb32fe9b022be295333ebfd4a15a29ec847de.png"></li> </ol> <p>结果就是上图的那样,根据 Jellyfin 的日志,插件 Jellyfin.Plugin.Template.dll 已被正确加载,但在 Visual Studio 的源码上却没有命中断点。</p> <p>我相信这实际上是一个 "visual studio 如何断点调试被 .exe 程序调用的 C# 类库?" 的问题,也查了 visual studio 文档 <a href="https://docs.microsoft.com/zh-cn/visualstudio/debugger/how-to-debug-from-a-dll-project?view=vs-2022" rel="nofollow">https://docs.microsoft.com/zh-cn/visualstudio/debugger/how-to-debug-from-a-dll-project?view=vs-2022</a></p> <p>但觉得这和 jellyfin 的文档 <a href="https://github.com/jellyfin/jellyfin-plugin-template" rel="nofollow">https://github.com/jellyfin/jellyfin-plugin-template</a> 有些出入,也可能是楼主对两个文档都没有正确理解,所以还是来这里请有经验的人帮忙了。</p>
收藏(0)  分享
相关标签: 灌水交流
注意:本文归作者所有,未经作者允许,不得转载
8个回复
  • ysc3839
    2022年4月26日 05:17
    调试器类型要选择“托管”(Managed),开始调试后,去模块列表找到你的 DLL ,确保调试符号已经加载
    0 0
  • userforg2021
    2022年4月26日 06:16
    试试插件入口点加一句 System.Diagnostics.Debugger.Launch(); 然后不使用 VS 调试,直接启动软件,正常情况下会弹出选择框让你选 VS 实例,选择打开了源码的 VS 就行了。
    0 0
  • wudicgi
    2022年4月26日 11:16
    如果你的 dll 文件和 exe 程序在同一解决方案内,那么一种简单的调试方法是,将 dll 的项目设为启动项目,同时配置启动的命令行为那个 exe 程序的完整路径
    0 0
  • hackfly
    2022年4月26日 11:49
    没加载符号,看不到代码内容的也调试不了。这还不如在 od 反汇编;在模块窗口,选中 DLL ,右键加载符号,看能不能加载符号
    0 0
  • yodhcn
    2022年4月26日 11:49
    你看我的 "第 1 条附言" 不是找不到符号,而是不知为何跳过了符号的加载
    0 0