What are these differences in two DLL file generat

2019-04-07 17:50发布

问题:

All my code is under source control, so I'm 100% sure that the source code hasn't changed. But if I build a C# DLL two times their content is slightly different. I can reproduce the problem 100% of the time by just building, and then building again.

This doesn't seem to impact the program at all, but tools like MSIMSP, used for creating patches from two MSI files are thrown off by these minute changes. Making patches (for my product) 40x bigger than they should be.

I've decompiled both DLLs and their assembly information, classes, etc... are exactly the same. The files are also exactly the same size, but of course have a different creation time. So I really cannot fathom what has changed.

So I dug a little deeper.

I've used WinDiff to find the changes and then cross referenced these in a hex editor. WinDiff shows a change in the second 'line' and in a line at about 80% of the file.

In the hex editor I see that the first byte that is changed is byte 0x088 (byte 136). This seems to be the only byte changed on this 'line'. I trouble finding the second change as WinDiff doesn't tell me the exact byte offset of the change.

Here is an image of the changes, the right file is the contents of the newer file.

Does anybody familiar with the make-up of (C#) DLL files know what the changed byte might mean? Or better yet how to make sure that DLL files stay exactly the same when you rebuild them?

回答1:

This might have something to do with differences between Build and a ReBuild

Difference between Build Solution, Rebuild Solution, and Clean Solution in Visual Studio?

if it doesn't think it needs to rebuild a project, it won't. It may also use partially-built bits of the project if they haven't changed

Performing a build uses metadata behind the scenes and thus your dll's can be different

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

SOLUTION:

You will need to perform a deterministic build as described here