3

I presume that if the C# code is unchanged, the generated IL will be the same each build. The problem is that 2 EXE files generated from the same code don't have the same hash.

I would like to check whether a change in code style generates a different IL. How can I achieve that?

Jader Dias
  • 88,211
  • 155
  • 421
  • 625
  • 3
    Every time you build a different binary will be produced, even if the code is identical (a build produces a GUID embedded in the assembly, which will be different on each compilation). – Oded Sep 14 '12 at 19:43
  • 1
    We may be able to help if you explain **why** you want a change in code style to generate different IL. – Dour High Arch Sep 14 '12 at 20:28
  • @DourHighArch I don't, I want to assure myself that nothing changed. – Jader Dias Sep 17 '12 at 13:26

3 Answers3

4

You are making a bad assumption. A rebuild without code change will deliver a different binary.

See:

https://stackoverflow.com/a/8927785/426894

Every time you run the compiler you should get a different output.

And

http://blogs.msdn.com/b/ericlippert/archive/2012/05/31/past-performance-is-no-guarantee-of-future-results.aspx

Is compiling the same C# program twice guaranteed to produce the same binary output?

No.

Community
  • 1
  • 1
asawyer
  • 17,642
  • 8
  • 59
  • 87
1

You can do this with ILSpy, an open-source .NET assembly browser and decompiler.

enter image description here

D'Arcy Rittich
  • 167,292
  • 40
  • 290
  • 283
1

There are some tools you can use to disassemble the EXE and compare their content. Look at this blog http://immitev.blogspot.com.br/2008/10/ways-to-compare-net-assemblies.html

[]'s

Fabio
  • 3,020
  • 4
  • 39
  • 62
  • By the way, there's a feature suggestion at Telerik's JustDecompile (another disassembler) site that fits your needs. I voted on this, let's help it gain attention from its developers: http://justdecompile.uservoice.com/forums/113277-justdecompile-feature-suggestions/suggestions/2664373-enable-a-feature-to-compare-versions-of-an-assembl – Fabio Sep 14 '12 at 19:57