为什么 C# 为相同的源代码生成不同的 EXE?

发布于 2024-08-03 04:51:47 字数 98 浏览 5 评论 0原文

每次我们重新编译 C# 应用程序时,最终都会得到具有不同 MD5 签名的 EXE。我们在同一台机器上重新编译,间隔几分钟。为什么相同的源代码不会产生相同的输出?有办法解决这个问题吗?

Every time we recompile our C# application we end up with EXEs with different MD5 signatures. We are recompiling on the same machine, minutes apart. Why doesn't the same source-code yield the same output? Is there a way to fix this?

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

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

发布评论

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

评论(6

り繁华旳梦境 2024-08-10 04:51:47

“因此每个程序集都有:

  1. 一个时间戳,位于两个位置
  2. 一个与 PDB 匹配的 GUID
  3. 每次编译时都会生成一个完全随机的 GUID。
  4. 一个指示程序集构建内容的计数器 - 仅在后续 Visual Studio 构建中生成。”

来自:

http://ritter.vg/#code_adventures_clr1

"So every assembly has:

  1. A Timestamp, in two locations
  2. A GUID that matched the PDB
  3. What appears to be a completely random GUID generated every compile.
  4. A counter indicating what the build of the assembly is - generated only in subsequent Visual Studio builds."

from:

http://ritter.vg/#code_adventures_clr1

你怎么敢 2024-08-10 04:51:47

我认为关键可能是“相隔几分钟”。如果 EXE 中有时间戳,那么就会改变 MD5 签名。

I think the key there might be "minutes apart". If there is a timestamp within the EXE, then that would alter the MD5 signature.

木緿 2024-08-10 04:51:47

我之前必须剖析这些案例,它似乎只是日期时间戳类型的更改(这是一个猜测)。如果将两个程序集放在 diff 工具下,您将看到 PE 中只有极少数行发生了更改;如果您更改少量代码并比较程序集,您将看到更大的差异。

这是我在研究识别“真正”差异与表面差异的工具时提出的一个问题:

.NET 程序集差异/比较工具 - 有哪些可用?

I've had to dissect these cases before and it appears to just be DateTime-stamp type changes (it's a guess). If you put both assemblies under diff tools you'll see only a very small number of lines in the PE have changed; if you change even a small amount of code and compare assemblies you'll see drastically larger differences.

Here's a question I opened while researching tools to identify "real" differences from superficial ones:

.NET Assembly Diff / Compare Tool - What’s available?

丢了幸福的猪 2024-08-10 04:51:47

程序集的版本号中很可能有几个 *。这会导致程序集版本号在构建时自动递增,这将导致输出的程序集出现明显差异。因此 MD5 校验和不同。

尝试将版本号切换到恒定的程序集版本,看看是否可以解决问题。

Most likely you have several *'s in the version number of the assembly. This causes the assembly version number to be auto-incremented on build which will cause a visible difference in the outputted assembly. Hence a different MD5 checksum.

Try switching the version number to a constant assembly version and see if that fixes the issue.

溺深海 2024-08-10 04:51:47

您可以尝试在两个 .exe 上运行 ildasm.exe(我的路径是 C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin)。

然后转储标题的原始视图,并将它们与 diff 工具进行比较。如果仍然没有差异,则可能是 PE 标头需要更高级的工具来发现。 Ildasm 为您提供 PE 标头大小和其他统计信息。

You could try running ildasm.exe (my path for this is C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin) on the two .exes.

Then dump out the raw view of the headers, and compare them with a diff tool. If there is still no difference, then it might be the PE headers which would need a more advanced tool to discover. Ildasm gives you the PE header size and other statistics on it though.

浅忆流年 2024-08-10 04:51:47

将有一个内置版本号,该版本号会随着每次构建而改变。

There will be a built in version number that will change with every build.

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