为什么 C# 为相同的源代码生成不同的 EXE?
每次我们重新编译 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
“因此每个程序集都有:
来自:
http://ritter.vg/#code_adventures_clr1
"So every assembly has:
from:
http://ritter.vg/#code_adventures_clr1
我认为关键可能是“相隔几分钟”。如果 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.
我之前必须剖析这些案例,它似乎只是日期时间戳类型的更改(这是一个猜测)。如果将两个程序集放在 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?
程序集的版本号中很可能有几个 *。这会导致程序集版本号在构建时自动递增,这将导致输出的程序集出现明显差异。因此 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.
您可以尝试在两个 .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.
将有一个内置版本号,该版本号会随着每次构建而改变。
There will be a built in version number that will change with every build.