1

I can't understand why If I compile the same source with Visual Studio 2008 (MSBuild) and then with csc (or NANT) at command line I can't obtain exacly the same binary file (the same assembly).

The command line is the same that is invoked by visual studio because I copy the command from the output window and then paste the command to the vs2008 command prompt.

I know that if I compile the same source at different time I obtain different binary because of the timestamps in the assembly metadata. In fact, if I compare two binaries produced by vs2008 at different time I notice small difference between the binary data.

But if I compile with vs and then with csc the binaries are very very different! Do you know why? What's wrong?

Assaf Lavie
  • 73,079
  • 34
  • 148
  • 203
Lorenzo Melato
  • 1,626
  • 1
  • 17
  • 16

4 Answers4

1

There's no guarantee of any particular order of metadata made by the compiler. That said, there's nothing intentionally causing a different ordering between the in-proc compiler and csc.exe.

0

A very bold guess, but maybe the environment variables are not the same in the VS IDE and your terminal. In a worse case scenario maybe your terminal version links against another .NET framework or at least against a couple of other libraries/ code files or compiler switches?

merkuro
  • 6,161
  • 2
  • 27
  • 29
  • @Scott: The timestamp issue explains why building two binaries at different times produces *slightly* different binaries - but not why the binaries built from the command-line are *very* different from the VS ones. – Jon Skeet Jun 13 '09 at 22:43
0

You haven't said whether you're building debug or binary builds in Visual Studio. I'm not sure that the command-line default is the same as either of them.

Try building with explicit /debug and /o switches (set to however you want them) and match them up in Visual Studio. Also define the DEBUG and/or TRACE symbols if you have them defined in the Visual Studio build configuration.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
0

@ Marc Gravell, Divo, Jon: I have try to disassemble the two assemplies with ILDASM. After a deep analysis and compare, I have see that the IL contents is exacly the same, but all the classes and methods, property getter and setter, etc. are in a very different order in the assembly! So if I compare the two assemblies with and hex editor/comparer I see a completely different binary body!

Now I need to understand why VS and Csc interacts with the compiler in this different way!

Do you have a reference to a document that explain the two approches?

Lorenzo Melato
  • 1,626
  • 1
  • 17
  • 16