Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
324 views
in Technique[技术] by (71.8m points)

c# - Why is a different dll produced after a clean build, with no code changes?

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 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?

This is using Visual Studio 2005 / WinForms.

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?

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

  • Two bytes in PE header at the start of the file.
  • <PrivateImplementationDetails>{guid} section
  • Cryptic part of the string table near the end (wonder why, I did not change the strings)
  • Parts of assembly info at the end of file.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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: A build-time-generated GUID. Always changes, every build.
  • AssemblyRef.HashValue: Could change if you're referencing another assembly that has also been rebuilt since the old build.

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!

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...