Why does C# generate different EXEs for the same source-code?
Asked Answered
A

6

13

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?

Allophane answered 26/8, 2009 at 15:8 Comment(1)
I guess you already have but... have you checked the manifest with IL DASM?Magellan
F
18

"So every assembly has:

  1. A Timestamp, in two locations
  2. A GUID that matched the PDB
  3. What appears to be a completely random GUID generated every compile.
  4. A counter indicating what the build of the assembly is - generated only in subsequent Visual Studio builds."

from:

http://ritter.vg/#code_adventures_clr1

Fruity answered 26/8, 2009 at 15:25 Comment(0)
P
4

I think the key there might be "minutes apart". If there is a timestamp within the EXE, then that would alter the MD5 signature.

Polka answered 26/8, 2009 at 15:12 Comment(1)
I've never examined the EXE produced by the C# compiler, and I haven't touched C# in over a year. But it would explain everything nicely, and it makes sense.Polka
R
2

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?

Rashad answered 26/8, 2009 at 15:10 Comment(0)
A
2

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.

Agateware answered 26/8, 2009 at 15:21 Comment(0)
D
2

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.

Duplication answered 26/8, 2009 at 15:30 Comment(1)
I strongly recommend use of the /source and /out flags.Factual
C
0

There will be a built in version number that will change with every build.

Cloudland answered 26/8, 2009 at 15:10 Comment(1)
Even if the assembly version is set statically to something like "1.0.0.0"? The only time a build-version should change is if you have it defined as "1.0.0.*" or manually change it, no?Rashad

© 2022 - 2024 — McMap. All rights reserved.