C# - 设置 pdb 的路径
有没有办法在 Visual Studio 2008 下的 C# 中设置程序数据库文件 (*.pdb) 的自定义路径?对于 C++,这非常简单(项目设置 -> 链接器 -> 调试 -> 生成程序数据库文件),但由于某种原因,Microsoft 似乎已为 C# 删除(或隐藏)它。
我知道“标准”用法是将 pdb 与可执行文件一起放置在 bin 目录中,但是该目录变得相当混乱,所以我真的更喜欢将它们放置在 /obj 中,这就是我的目录总是用C++来做。
谢谢!
Is there any way to set a custom path to Program Database files (*.pdb) in C# under Visual Studio 2008? With C++ this was quite simple (Project settings -> Linker -> Debugging -> Generate Program Database File), but for some reason Microsoft seems to have removed (or hidden) it for C#.
I'm aware that the "standard" usage is to have pdb's located in the bin dir alongside the executable, but that directory is becoming quite a mess so I'd really prefer for them to be located in /obj, which is what I always used to do in C++.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
C# 编译器通过 /pdb 命令行选项 来支持此功能。然而,该选项并未在 IDE 的“构建”选项卡中公开。
IDE 构建过程已要求 C# 编译器将 .pdb 文件放入 obj\Debug 目录中。它的副本最终由名为 CopyFilesToOutputDirectory 的 MSBuild 任务保存在 bin\Debug 中。此任务在 Microsoft.Common.targets 中配置,该文件位于 VS2008 的 c:\windows\microsoft.net\framework\v3.5 目录中。从技术上讲,您可以编辑此文件并删除复制 .pdb 的
元素。请注意文件顶部的警告,请务必在修改之前制作备份副本。我认为这样做会遇到的基本问题是,这会影响所有项目的所有构建。并且调试器现在无法再找到 .pdb 文件。那将是最终的终结者。
The C# compiler supports this with the /pdb command line option. That option is however not exposed in the IDE's Build tab.
The IDE build process already asks the C# compiler to put the .pdb file in the obj\Debug directory. A copy of it ends up in the bin\Debug by a MSBuild task named CopyFilesToOutputDirectory. This task is configured in Microsoft.Common.targets, a file located in the c:\windows\microsoft.net\framework\v3.5 directory for VS2008. You could technically edit this file and remove the
<Copy>
element that copies the .pdb. Heed the warning at the top of file, be sure to make a backup copy before you modify it.I think the basic problem you'll encounter doing this is that this affects all builds of all projects. And that the debugger now no longer can find the .pdb file. That would be the ultimate show-stopper.
添加构建后事件并将 pdb 复制到所需位置)
add postbuild event and copy a pdb to desired location)
.pdb 文件必须与 .exe 和 .dll 文件位于同一文件夹中才能加载。
Pdb 文件在异常处理时加载,并且需要追溯到代码中发生异常的确切行。
您可以做的是在构建期间将 pdb 移动到符号服务器,而不是与应用程序一起发布它们。然后在分析异常跟踪时将它们拉进来。
查看 这篇文章了解有关 pdb 文件、符号服务器等的信息。
The .pdb files has to reside in the same folder as your .exe and .dll's in order to load.
Pdb files are loaded upon exception handling, and needed for tracing back to the exact line in the code where your exceptions happens.
What you can do is move the pdb's to a symbol server during build instead of publishing them with the application. Then pull them in when analyzing an exception trace.
Check out this post for information about pdb files, symbol servers and more.