Jaa


When CSC.Exe Generates a Different Size of Assembly From VS IDE

I struggled for the reason why CSC.EXE results in an assembly differently from VS IDE, because VS IDE generates an assembly of 20KB while CSC.exe compiles it in 8KB with the same source code.

I checked the compiler options for the two compilers, but I couldn’t find any big difference. I didn’t except it, but I simply copied the compiler command shown in the output window of VS IDE and executed the same one in the command line window..Wow. The same command line generated the assembly of 8 KB, which were 20KB in VS IDE with the same compiler options..

To figure out  which compiler options and how VS IDE actually passed to CSC.exe, I tried the process explorer and the Gflag tools to hook into the csc.exe execution….but, I couldn’t because VS IDE uses a different mechanism to run the compiler.  I disassembled them and checked the differences, but no big difference.

The actually reason is that I migrated the project from the previous version of VS IDE to 2005. In the previous version, the default File alignment has been changed for the new version. The default value of the setting was 4096, but now it is 512. I don't why though.

To have change the option for CSC.exe, you can use the "/filealign" option. If you want to change the setting in VS IDE, you can do that by setting File Alignment in the Advanced Build Settings dialog box. Capture8-30-2007-5.04.54 PM

Young

Technorati Tags: C#

Comments

  • Anonymous
    September 27, 2007
    PingBack from http://www.artofbam.com/wordpress/?p=3538

  • Anonymous
    September 27, 2007
    So, we can conclude that assemblies generated by VS IDE and CSC.EXE for a project (no converted from earlier version) will be same. Am I right?

  • Anonymous
    September 27, 2007
    Yes, I think both of the assemblies are same...