Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 468
dbkk Avatar asked Sep 20 '08 05:09

dbkk


People also ask

Can a DLL contain another DLL?

You can certainly embed another DLL as a resource and extract and load it at runtime if that's what you need.

Can you edit DLL in Visual Studio?

Can you edit DLL files in Visual Studio? Yes, you can open and edit certain DLL resources within Visual Studio. You can use Visual Studio to add, extract or delete certain graphical or textual resources, but you cannot edit the functions of a DLL file.

Why we use DLL in C#?

DLL in the C# Programming Language. The Class Library . DLL contains program code, data, and resources that can be can used by other programs and are easily implemented into other Visual Studio projects.

How do I save a Visual Studio as DLL?

Open your Visual Studio 2015 preview, go to the file menu, go to the new, go with the project, from the template field select C#, select Class Library then name it as you want. Save it at an appropriate place. So from the browse button you can select the appropriate location for saving the DLL.


2 Answers

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!
like image 61
Alex Lyman Avatar answered Oct 14 '22 10:10

Alex Lyman


I think that would be the TimeDateStamp field in the IMAGE_FILE_HEADER header of the PE32 specifications.

like image 41
Magnus Johansson Avatar answered Oct 14 '22 12:10

Magnus Johansson