为什么在 .NET 中分发应用程序的调试版本是一种不好的做法?

发布于 2024-10-18 16:06:20 字数 571 浏览 2 评论 0原文

阅读 这个问题,在第一条评论中,@Cody Gray 说:

呃,你知道你不应该 重新分发“调试”版本, 对吗?

我很担心。在 Visual Studio 中,我通常在调试模式下开发应用程序,如果我需要分发可执行文件,我所做的就是压缩 .exe 和所需的 .dll 文件(在 bin\Debug 文件夹中)。

为什么这是一个坏主意?

这样做与在发布模式下执行完全相同的操作有什么区别?

编辑:
我不久前问过这个问题,但我只是想编辑它以添加差异:

在代码中使用 Debug.Assert 来测试它时,并在发布模式下编译,所有这些线都消失了,所以这可能是另一个区别。

Reading this question, in the first comment, @Cody Gray says:

Erm, you know that you're not supposed
to redistribute the "Debug" version,
right?

I'm concerned about it. In Visual Studio, I usually develop my applications in Debug mode, and if I need to distribute the executable, all I do is zip the .exe and required .dll files (in bin\Debug folder).

Why is it a bad idea?

What is the difference between doing this and doing exactly the equivalent thing in Release mode?

Edit:
I asked this question time ago, but I just wanted to edit it to add a difference:

When using Debug.Assert in the code to test it, and compile in Release Mode, all those lines are gone, so that could be another difference.

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

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

发布评论

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

评论(5

眼眸里的那抹悲凉 2024-10-25 16:06:21

这取决于您使用哪种语言来开发程序。当您使用 C++ 时,您会获得 /RTC 的开销和“编辑 + 继续”支持。它们会大大减慢生成的代码速度,并且如果您使用递归,您的应用程序很可能会在 StackOverflow 上早期崩溃。如果没有调试器,从检查代码中获得的运行时异常可能很难诊断。

如果您使用 VB.NET,那么当您使用不带调试器的调试版本时,您很容易会出现不可插入的内存泄漏。其“编辑 + 继续”支持代码中的缺陷会导致包含 WithEvents 事件的类的每个实例泄漏 WeakReference。您的应用程序最终会因 OutOfMemory 异常而终止。

如果您使用 C#,那么不会出错,只是 JIT 编译器无法生成优化的机器代码,并且垃圾收集效率不高。您的程序将运行缓慢并且消耗比必要的更多的内存。这也适用于 VB.NET 和 C++/CLI。

程序员在编写代码时通常首先考虑的是性能。因此,发布调试版本有点亵渎。然而,大量程序通常完全受到 I/O、磁盘、网卡或数据库服务器的限制。在这种情况下,原始 cpu 性能并不重要。

It depends on what kind of language you use to develop your program. When you use C++, you get the overhead of /RTC and the Edit + Continue support. They slow down the generated code by a great deal and make it likely your app crashes early on a StackOverflow if you use recursion. The runtime exceptions you can get from the checking code can be hard to diagnose without a debugger.

If you use VB.NET then you'll easily have a unpluggable memory leak when you use the Debug build without a debugger. A flaw in its Edit + Continue support code causes a WeakReference to be leaked for every instance of a class that contains a WithEvents event. Your app eventually dies on an OutOfMemory exception.

If you use C# then not a heckofalot goes wrong, the JIT compiler is just prevented from generating optimized machine code and garbage collection isn't as efficient. Your program will run slow and consume more memory than necessary. This applies to VB.NET and C++/CLI as well.

Perf is usually foremost on a programmer's mind when writing code. As such, shipping the debug build is a bit blasphemous. A significant number of programs are however completely throttled by I/O, the disk, network card or the dbase server typically. Raw cpu perf doesn't matter a great deal in that case.

凉栀 2024-10-25 16:06:21

我认为性能是一个问题,这篇文章有更多详细信息

I think performance is an issue, this post has more detail

半寸时光 2024-10-25 16:06:21

纯 C# 或 VB.NET 应用程序可以在安装了正确的 .NET 框架 redist 的任何计算机上运行,​​但 C++ 或 C++/CLI 应用程序(或混合应用程序)需要 VC redist 包,该包不包含调试版本所需的库。假设您的用户 PC 上未安装 Visual Studio,仅安装了可再发行包,我想说您面临程序的调试版本可能无法在那里工作的风险。

A pure C# or VB.NET application may work on any machine with the right .NET framework redist being installed, but a C++ or C++/CLI application (or a mixed application) needs the VC redist package, which does not contain the debug versions of the needed libraries. Assuming that on your users PC Visual Studio is not installed, only a redistributable package, I would say you have the risk that a debug version of your program simply might not work there.

葵雨 2024-10-25 16:06:21

还有法律原因——
引用:
“请注意,应用程序的调试版本不可重新分发,并且各种 Visual C++ 动态链接库 (DLL) 的调试版本均不可重新分发。”
来自重新分发 Microsoft Visual C++ 6.0 应用程序

这是针对 Visual Studio 2010“确定要重新分发的 DLL”:
“您无法重新分发 Visual Studio 中包含的所有文件;您只能重新分发 Redist.txt 中指定的文件。应用程序的调试版本和各种 Visual C++ DLL 不可重新分发。来自 确定要重新分发哪些 DLL

There are legal reasons also -
Quote:
"Note that debug versions of an application are not redistributable and that none of the debug versions of various Visual C++ dynamic-link libraries (DLLs) are redistributable."
From Redistributing Microsoft Visual C++ 6.0 Applications

And this is for Visual Studio 2010 "Determining Which DLLs to Redistribute":
"You cannot redistribute all of the files that are included in Visual Studio; you are only permitted to redistribute the files that are specified in Redist.txt. Debug versions of applications and the various Visual C++ DLLs are not redistributable. From Determining Which DLLs to Redistribute

舟遥客 2024-10-25 16:06:21

关于性能,我有兴趣了解一些有关调试与发布的指标。

虽然我确信指标会根据应用程序的具体功能而有所不同,但我的预感是,大多数时候最终用户不会知道其中的差异。

Regarding performance, I'd be interested to see some metrics about debug versus release.

Whilst I'm sure the metrics would vary depending on exactly what the application does, but my hunch is that most of the time the end user wouldn't know the difference.

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