为什么在没有代码更改的情况下干净构建后会生成不同的 dll? [英] Why is a different dll produced after a clean build, with no code changes?

查看:26
本文介绍了为什么在没有代码更改的情况下干净构建后会生成不同的 dll?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我干净地构建我的 C# 项目时,生成的 dll 与之前构建的 dll 不同(我单独保存了它).没有更改代码,只是清理和重建.

When I do a clean build my C# project, the produced dll is different then the previously built one (which I saved separately). No code changes were made, just clean and rebuild.

Diff 显示 DLL 中的一些字节发生了变化——开始时很少,接近结尾时很少,但我无法弄清楚这些代表什么.有没有人了解为什么会发生这种情况以及如何预防?

Diff shows some bytes in the DLL have changes -- few near the beginning and few near the end, but I can't figure out what these represent. Does anybody have insights on why this is happening and how to prevent it?

这是使用 Visual Studio 2005/WinForms.

This is using Visual Studio 2005 / WinForms.

更新:不使用自动版本递增或对程序集进行签名.如果它是某种时间戳,如何防止 VS 编写它?

Update: Not using automatic version incrementing, or signing the assembly. If it's a timestamp of some sort, how to I prevent VS from writing it?

更新:查看 Ildasm/diff 后,似乎以下项目有所不同:

Update: After looking in Ildasm/diff, it seems like the following items are different:

  • 文件开头的 PE 标头中的两个字节.
  • {guid} 部分
  • 接近末尾的字符串表的神秘部分(不知道为什么,我没有更改字符串)
  • 文件末尾的部分装配信息.

不知道如何消除其中任何一个,如果可能的话...

No idea how to eliminate any of these, if at all possible...

推荐答案

我最好的猜测是,您看到的更改字节是在构建时自动生成的内部使用的元数据列.

My best guess would be the changed bytes you're seeing are the internally-used metadata columns that are automatically generated at build-time.

某些 Ecma-335 Partition II(CLI 规范元数据定义)列可以随构建更改,即使源代码根本没有更改:

Some of the Ecma-335 Partition II (CLI Specification Metadata Definition) columns that can change per-build, even if the source code doesn't change at all:

  • Module.Mvid:构建时生成的 GUID.每次构建总是在变化.
  • AssemblyRef.HashValue:如果您正在引用另一个自旧版本以来也已重建的程序集,则可能会发生变化.

如果这真的很困扰您,我最好的提示是找出正在发生变化的确切内容是对实际的元数据表进行差异化.获取这些的方法是使用 ildasm MetaInfo 窗口:

If this really, really bothers you, my best tip on finding out exactly what is changing would be to diff the actual metadata tables. The way to get these is to use the ildasm MetaInfo window:

View > MetaInfo > Raw:Header,Schema,Rows // important, otherwise you get very basic info from the next step

View > MetaInfo > Show!

这篇关于为什么在没有代码更改的情况下干净构建后会生成不同的 dll?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆