Why does Visual Studio 2005 generate the .pdb
files when compiling in release? I won't be debugging a release build, so why are they generated?
相关问题
- Generic Generics in Managed C++
- How to know full paths to DLL's from .csproj f
- Importing NuGet references through a local project
- How to Debug/Register a Permanent WMI Event Which
- Visual Studio 2019 - error MSB8020: The build tool
Because without the PDB files, it would be impossible to debug a "Release" build by anything other than address-level debugging. Optimizations really do a number on your code, making it very difficult to find the culprit if something goes wrong (say, an exception is thrown). Even setting breakpoints is extremely difficult, because lines of source code cannot be matched up one-to-one with (or even in the same order as) the generated assembly code. PDB files help you and the debugger out, making post-mortem debugging significantly easier.
You make the point that if your software is ready for release, you should have done all your debugging by then. While that's certainly true, there are a couple of important points to keep in mind:
You should also test and debug your application (before you release it) using the "Release" build. That's because turning optimizations on (they are disabled by default under the "Debug" configuration) can sometimes cause subtle bugs to appear that you wouldn't otherwise catch. When you're doing this debugging, you'll want the PDB symbols.
Customers frequently report edge cases and bugs that only crop up under "ideal" conditions. These are things that are almost impossible to reproduce in the lab because they rely on some whacky configuration of that user's machine. If they're particularly helpful customers, they'll report the exception that was thrown and provide you with a stack trace. Or they'll even let you borrow their machine to debug your software remotely. In either of those cases, you'll want the PDB files to assist you.
Profiling should always be done on "Release" builds with optimizations enabled. And once again, the PDB files come in handy, because they allow the assembly instructions being profiled to be mapped back to the source code that you actually wrote.
You can't go back and generate the PDB files after the compile.* If you don't create them during the build, you've lost your opportunity. It doesn't hurt anything to create them. If you don't want to distribute them, you can simply omit them from your binaries. But if you later decide you want them, you're out of luck. Better to always generate them and archive a copy, just in case you ever need them.
If you really want to turn them off, that's always an option. In your project's Properties window, set the "Debug Info" option to "none" for any configuration you want to change.
Do note, however, that the "Debug" and "Release" configurations do by default use different settings for emitting debug information. You will want to keep this setting. The "Debug Info" option is set to "full" for a Debug build, which means that in addition to a PDB file, debugging symbol information is embedded into the assembly. You also get symbols that support cool features like edit-and-continue. In Release mode, the "pdb-only" option is selected, which, like it sounds, includes only the PDB file, without affecting the content of the assembly. So it's not quite as simple as the mere presence or absence of PDB files in your
/bin
directory. But assuming you use the "pdb-only" option, the PDB file's presence will in no way affect the run-time performance of your code.* As Marc Sherman points out in a comment, as long as your source code has not changed (or you can retrieve the original code from a version-control system), you can rebuild it and generate a matching PDB file. At least, usually. This works well most of the time, but the compiler is not guaranteed to generate identical binaries each time you compile the same code, so there may be subtle differences. Worse, if you have made any upgrades to your toolchain in the meantime (like applying a service pack for Visual Studio), the PDBs are even less likely to match. To guarantee the reliable generation of ex postfacto PDB files, you would need to archive not only the source code in your version-control system, but also the binaries for your entire build toolchain to ensure that you could precisely recreate the configuration of your build environment. It goes without saying that it is much easier to simply create and archive the PDB files.
PDB can be generated for
Release
as well as forDebug
. This is set at (in VS2010 but in VS2005 must be similar):Just change it to
None
..PDB file is the short name of "Program Database". It contains the information about debug point for debugger and resources which are used or reference. Its generated when we build as debug mode. Its allow to application to debug at runtime.
The size is increase of .PDB file in debug mode. It is used when we are testing our application.
No need of this file when release or deploy. Good article of pdb file.
http://www.codeproject.com/Articles/37456/How-To-Inspect-the-Content-of-a-Program-Database-P
Debug symbols (.pdb) and XML doc (.xml) files make up a large percentage of the total size and should not be part of the regular deployment package. But it should be possible to access them in case they are needed.
One possible approach: at the end of the TFS build process, move them to a separate artifact.
Why are you so sure you will not debug release builds? Sometimes (hopefully rarely but happens) you may get a defect report from a customer that is not reproducible in the debug version for some reason (different timings, small different behaviour or whatever). If that issue appears to be reproducible in the release build you'll be happy to have the matching pdb.
In a multi-project solution, you usually want to have one configuration that generates no PDB or XML files at all. Instead of changing the
Debug Info
property of every project tonone
, I thought it would be more expedient to add a post-build event that only works in a specific configuration.Unfortunately, Visual Studio doesn't allow you to specify different post-build events for different configurations. So I decided to do this manually, by editing the
csproj
file of the startup project and adding the following (instead of any existingPostBuildEvent
tag):Unfortunately, this will make the post build event textbox blank and putting anything in it can have unpredictable results.