简体   繁体   中英

C# - Set path to pdb

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!

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.

添加postbuild事件并将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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM