C# 发行版仍然有 .pdb 文件

发布于 2024-08-24 09:50:43 字数 342 浏览 8 评论 0原文

我想部署用 C# 完成的应用程序的发行版本。

当我使用 Release 配置进行构建时,我仍然可以看到生成了 .pdb 文件,这意味着我的应用程序仍然可以调试。这也意味着我的代码中存在一些调试信息,从而稍微减慢了速度。

如果这是真的,我如何才能完全抑制二进制文件中生成的任何调试信息?您是否也知道发布 .pdb 的原因? Release 配置已选中Optimize code,并且仅定义了TRACE 常量,而不是DEBUG

感谢您的协助。

I want to deploy the release version of my application done in C#.

When I build using the Release config, I still can see that .pdb files are produced, meaning that my application can be still debugged. This also means that some debug information is present somewhere in my code, slowing it down a little bit.

If this is true, how can I completely suppress any debug information produced in the binaries? Do you also know the reason of for having release .pdb? The Release configuration has the Optimize code checked, and only the TRACE constant is defined, not DEBUG.

Thank you for assisting.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

娇女薄笑 2024-08-31 09:50:43

如果要禁用 pdb 文件生成,则需要在单击位于的“高级...” 按钮后使用项目属性中提供的“高级构建设置” 对话框在 Build 选项卡的下部

Output - Debug info: 设置为 None 以进行发布构建配置,并且不会生成 pdb 文件。

If you want to disable pdb file generation, you need to use the "Advanced build settings" dialog available in project properties after clicking the "Advanced..." button" located in the lower part of the Build tab.

Set Output - Debug info: to None for release build configuration and no pdb files will be generated.

混浊又暗下来 2024-08-31 09:50:43

默认情况下也会为发布版本生成 PDB。这是一项功能,您不应该禁用它。生成 PDB 意味着您可以在调试时获得更多信息。 PDB 文件的存在不会以任何方式影响代码的性能。

The default is to generate PDBs for release builds as well. That is a feature and you shouldn't disable it. Generating PDBs means you can get more information when debugging. The performance of the code is not affected in any way by the presence of PDB files.

痴骨ら 2024-08-31 09:50:43

您不必在发布部署中附带 .PDB,但保留它们很有用 - 例如,您可以使用计算机上的 PDB 远程调试在不同计算机上运行的代码,以获取异常的行号发生。

如果不使用 .PDB,行号和文件名不会包含在堆栈跟踪中,因此调试它们会变得更加困难。

You don't have to ship the .PDBs with your release deployment, but they are useful to keep around - for example you can remotely debug the code running on a different machine using the PDBs on your machine to get the line numbers of where exceptions occur.

Without the use of the .PDBs, line numbers and file names are not included in stacktraces so it makes it much harder to debug them.

欢烬 2024-08-31 09:50:43

您可以在 Build -> 下的项目属性中控制 pdb/符号生成。高级...->调试信息:.选项包括:

  • (无符号信息)
  • 完整(将生成 .pdb,并且一些符号信息嵌入到程序集中)
  • 仅 pdb< /strong> (将生成 .pdb,但程序集不受影响)

请参阅 http://msdn.microsoft.com/en-us/library/8cw0bt21%28VS.80%29.aspx 了解更多信息。

强烈建议您选择仅 pdb 选项,选择 none 选项,因为它仍然为您提供一些符号信息而不影响程序集 - 您可能会发现这是您的发布版本中的当前设置。

You control pdb / symbol generation in the project properties under Build -> Advanced... -> Debug info:. The options are:

  • none (no symbol information)
  • full (a .pdb will be produced, and some symbol information is embedded in the assembly)
  • pdb-only (a .pdb will be produced but the assembly is not impacted)

See http://msdn.microsoft.com/en-us/library/8cw0bt21%28VS.80%29.aspx for more information.

I strongly recommend that you choose the pdb-only option, not the none option as it still gives you some symbol information without affecting the assembly - you will probably find that this is the current setting you have on your release builds.

裸钻 2024-08-31 09:50:43

让编译器生成 .pdb 文件与优化代码并不相互排斥。

有关此主题的更多信息,请阅读这些 博客 条目

Having the compiler generate a .pdb file is not mutually exclusive to having it optimize the code.

For more info on this subject, read these blog entries.

淡淡離愁欲言轉身 2024-08-31 09:50:43

编译后的 EXE 文件包含 PDB 文件的路径。该路径可以轻松包含您的姓名,并且是文件结构的提示。我不想分享这个私人信息!

为了从 EXE 文件中删除 PDB 文件的路径而不丢失调试信息,您可以将 PDB 文件嵌入 EXE 文件中。

属性=>构建=>高级(构建设置)=>调试信息=>
嵌入式

The compiled EXE file contains the path to the PDB file. The path could easily include your name and is a hint of your file structure. I don't like to share this private information!

In order to remove the path of the PDB file out of the EXE file without loosing debug info, you could embed the PDB file inside the EXE file.

Properties => Build => Advanced (Build Settings) => Debuginfo =>
Embedded

遮云壑 2024-08-31 09:50:43

对于包含大量项目的解决方案,转到所有不同的项目设置来禁用/启用 pdb 文件生成可能会很乏味。

或者,他们可以使用主项目上的构建后命令或 bat 文件中的 del /S *.pdb wither 来删除它们,这样您就可以选择是否运行它,而无需进行编辑所有项目文件。

从构建后事件示例:

if $(ConfigurationName) == Release del /S $(TargetDir)*.pdb

In the case of a solution with lots of projects, it can be tedious to go to all the different projects settings to disable / enable the pdb file generation.

Alternatively, they can delete them using del /S *.pdb wither from post build command on the main project or from a bat file, which allows you to choose whether to run it or not without having to edit all project files.

From post build event example:

if $(ConfigurationName) == Release del /S $(TargetDir)*.pdb
莳間冲淡了誓言ζ 2024-08-31 09:50:43

我将此属性组添加到我的 SDK 样式 .csproj:

<PropertyGroup Condition="$(Configuration.Contains('Release')) ">
    <DebugType>none</DebugType>
</PropertyGroup>

它不会为包含字符串 Release 的任何配置生成 .pdf 文件。

I added this property group to my SDK style .csproj:

<PropertyGroup Condition="$(Configuration.Contains('Release')) ">
    <DebugType>none</DebugType>
</PropertyGroup>

It is not generating .pdf files for any configuration that contains string Release.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文