C# Frequently Asked Questions

The C# team posts answers to common questions

What does the /target: command line option do in the C# compiler?

All the /target: options except module create .NET assemblies. Depending on the option, the compiler adds metadata for the operating system to use when loading the portable executable (PE) file and for the runtime to use in executing the contained assembly or module.

module creates a module. The metadata in the PE does not include a manifest. Module/s + manifest make an assembly - the smallest unit of deployment. Without the metadata in the manifest, there is little the runtime can do with a module.

library creates an assembly without an entry point, by setting the EntryPointToken of the PE's CLR header to 0. If you look at the IL, it does not contain the .entrypoint clause. The runtime cannot start an application if the assembly does not have an entry point.

exe creates an assembly with an entry point, but sets the Subsystem field of the PE header to 3 (Image runs in the Windows character subsystem - see the _IMAGE_OPTIONAL_HEADER structure in winnt.h). If you ILDASM the PE, you will see this as .subsystem 0x0003. The OS launches this as a console app.

winexe sets the Subsystem field to 2. (Image runs in the Windows GUI subsystem). The OS launches this as a GUI app.

[Author: SantoshZ]
See also:
Chapter 3 of Inside Microsoft .NET IL assembler (Serge Lidin, Microsoft Press)
Metadata and the PE File Structure at MSDN
An In-Depth Look into the Win32 Portable Executable File Format - Part 1 and Part 2 (Matt Pietrek, MSDN Magazine)

Published Saturday, December 04, 2004 11:33 PM by CSharpFAQ

Comments

 

Syed Faraz Mahmood said:

why can't we add reference to the .exe assemblies, in vs.net.(or thru compiler command line, )

the csc /r option docs says that it requires files of .dll extension coz there "only one .exe assembly can be loaded per process,"

if this is what happens when we load an .exe assembly using reflection :)
expalanation needed badly
take care
December 11, 2004 12:43 AM
 

FAQ C# said:

December 19, 2004 8:16 PM
 

FAQ C# (par Yannick Lejeune) said:

August 23, 2005 5:12 AM
 

What does the /target: command line option do in the C# compiler? said:

November 26, 2007 7:14 AM
 

C Frequently Asked Questions What does the target command line | Portable Greenhouse said:

June 1, 2009 7:29 AM
Anonymous comments are disabled

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker