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

Published 04 December 04 11:33 PM

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)

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Syed Faraz Mahmood said on December 11, 2004 12:43 AM:
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
# FAQ C# said on December 19, 2004 8:16 PM:
# FAQ C# (par Yannick Lejeune) said on August 23, 2005 5:12 AM:
# What does the /target: command line option do in the C# compiler? said on November 26, 2007 7:14 AM:

PingBack from http://feeds.maxblog.eu/item_802200.html

# C Frequently Asked Questions What does the target command line | Portable Greenhouse said on June 1, 2009 7:29 AM:

PingBack from http://portablegreenhousesite.info/story.php?id=15271

Leave a Comment

(required) 
(optional)
(required) 

  
Enter Code Here: Required

This Blog

Syndication

Page view tracker