The Microsoft® Shared Source implementation of the C# 2.0 compiler is very similar to the implementation in the Microsoft® .NET Framework SDK and Microsoft® Visual Studio® 2005. Both implementations originate from the same source base but some options and features that rely on functionality in Microsoft® Windows® have been removed from the Shared Source implementation.
The application file for the C# compiler is named csc.exe on Windows.
The following option areas and related options were modified
Complete documentation for the .NET Framework C# compiler and tutorials is available on msdn.microsoft.com. Other than the changes mentioned above, the functionality in the Shared Source implementation of the C# compiler is the same as the .NET Framework implementation.
Note: Because the C# compiler builds complete portable executable (PE) files (.exe files, .dll files, and .netmodule files) it can be considered a compiler and linker. The compiler has linker-style options that set Windows-specific information in the generated PE file. The Shared Source CLI (SSCLI) loads applications using the clix loader and does not use the Windows system loader. Windows-specific settings that affect file loading are ignored when files are loaded into the SSCLI. However, if an assembly built with the Shared Source implementation of the C# compiler is executed under the .NET Framework, the file is first loaded by the system loader and the information in the PE file does change the Windows PE file loading behavior. The Shared Source C# compiler does make the required modifications to the PE file but these changes are only used by the Windows loader and not by the clix loader.
Some of the options to which this note applies are:
The compiler produces PE format executable (.exe) files, dynamic-link libraries (DLLs), or code modules (.netmodule files). For information on the PE format of files loaded by ECMA CLI implementations see the ECMA-335 Common Language Infrastructure specification, Partition II, section 24.
For information on how the Shared Source CLI (SSCLI) implementation loads PE files, see the implementation code for the clix application loader: sscli20\clr\src\tools\clix.
The C# compiler can be invoked at the command line by typing the name of the executable file on the command line. For more details on correctly setting your environment to build and execute SSCLI utilities including the C# compiler, see env.html
The C# compiler code uses the following rules when interpreting arguments given on the operating system command line:
Every compiler option is available in two forms: -option and /option.
Option | Description | |
---|---|---|
@response_file | Specifies a response file, response_file. The
@ option lets you specify a file that contains compiler options and source code
files to compile. These compiler options and source code files will be processed
by the compiler just as if they had been specified on the command line. For example:
|
|
/? | Outputs compiler options to the console. Same as
/help. This option sends a listing of compiler options, and a brief description of each option, to stdout. If this option is included in a compilation, no output file will be created and no compilation will take place. |
|
/addmodule:file[;file2] | Specifies one or more modules (file, file2, and
so on) to be part of this assembly.
All modules added with /addmodule must be in the same directory as the output
file at run time. That is, you can specify a module in any directory at compile
time but the module must be in the application directory at run time. If the
module is not in the application directory at run time, you will get a
System.TypeLoadException. |
|
/baseaddress:address_value | Specifies the preferred base address (address_value) at which to load a
DLL.
The loading base address is only relevant if the file is going to be run on the .NET Framework on Windows. Differences in loading behavior can occur in the .NET Framework on Windows depending on the version of the Windows operating system. The SSCLI implementation ignores base address information stored in the PE assembly file. For information on the PE format of files loaded by ECMA CLI implementations see the ECMA-335 Common Language Infrastructure specification, Partition II, section 24. For more information on DLL base addresses in Windows, go to msdn.microsoft.com and search for "dll base address". The Microsoft Windows Platform SDK tool Rebase.exe documentation and the Microsoft Visual Studio Linker.exe documentation also provide detailed information. |
|
/checked[+ | -] | Specifies whether integer arithmetic that overflows the bounds of the data type will cause an exception at run time.
The /checked option specifies whether an integer arithmetic statement that is
not in the scope of the checked or unchecked keywords and that results in a
value outside the range of the data type shall cause a run-time exception. |
|
/codepage:id | Specifies the code page to use for all source code files
in the compilation with id. If you compile one or more source code
files that were not created to use the default code page on your computer, you
can use the -codepage option to specify which code page should be used. |
|
/debug[+ | -] /debug:{full | pdbonly} |
Emits debugging information. The /debug option causes the compiler to generate debugging information and place it in the output file. Use this option to create debug builds. If /debug, /debug+, or /debug:full is not specified, you will not be able to debug the output assembly at the source code level. Options values:
Specifying +, or just /debug, causes the compiler to generate debugging information and place it in a program database (.ildb file). Specifying -, which is in effect if you do not specify /debug, prevents debug information from being created.
These arguments specify the type of debugging information generated by the compiler. The full argument, which is in effect if you do not specify /debug:pdbonly, enables attaching a debugger to the running program. Specifying pdbonly allows source code debugging when the program is started in the debugger, but will display CIL only when the running program is attached to the debugger. |
|
/define:name[;name2] | Defines preprocessor symbols where name and name2
are the names of one or more symbols that you want to define. The /define option defines name as a symbol in your program. It has the
same effect as using a #define preprocessor directive in your source file. A
symbol remains defined until an #undef directive in the source file removes the
definition or the compiler reaches the end of the file. The short form of /define is /d. You can define multiple symbols with /define by using a semicolon or comma to separate symbol names. For example:
|
|
/filealign:number | Specifies the size of sections in the output binary file where
number has values of 512, 1024, 2048, 4096, 8192, or 16384. These values are in
bytes.
The information stored in the PE file as the result of using this option is not used on the SSCLI implementation of the CLI assembly loader. |
|
/fullpaths | Specifies the absolute path to the file in compiler output. By default, errors and warnings that result from compilation specify the name of the file in which an error was found. The /fullpaths option causes the compiler to specify the full path to the file. |
|
/help | Outputs compiler options to the console. Same as
/?. This option sends a list of compiler options, and a brief description of each option, to stdout. If this option is included in a compilation, no output file will be created and no compilation will take place. |
|
/incremental[+ | -] | Enables incremental compilation of source code files. The /incremental compiler option enables the incremental compiler, which compiles only those methods that have changed since the last compilation. Information about the state of the previous compilation is stored in the following file, which is created by the compiler:
When compiling with /debug, the status of debug information is stored in the program database (.ildb file). Information about the status of the compilation, other than debug information, is stored in an .incr file. For example:
|
|
/lib:dir1[, dir2] | Specifies the location of assemblies that will be referenced
through the /reference option
where dir1 is a directory for the compiler to look in if a referenced
assembly is not found in the current working directory (the directory from which
you are invoking the compiler) or in the CLI implementation assembly directory
and dir2 is one or more additional directories to search in to resolve assembly
references.
Separate additional directory names with a comma. The /lib option specifies the location of assemblies referenced through the
/reference option.
Use /reference to specify an assembly reference. |
|
/linkresource:filename[,identifier] | Creates a link to a managed resource where filename
is the resource file to which you want to link from the assembly and
identifier (optional) is the logical name for the resource (the name used in
code to load the resource). The default identifier is the file name. The /linkresource option creates a link to a resource in the output
file; the resource file is not placed in the output file. The /resource option
embeds a resource file in the output file. |
|
/main:class | Specifies the location of the Main method where class
is the type that contains the Main method. If your compilation includes more than one type with a Main method, the /main option allows you to specify which type contains the Main method that you want to use as the entry point into the program. This option is only for use when compiling an .exe file. |
|
/nologo | Suppresses compiler banner information. The /nologo option suppresses the display of the sign-on banner when the compiler starts up and suppresses the display of informational messages during compiling. |
|
/nostdlib[+ | -] | Prevents the default importation of the base class library (mscorlib.dll). The /nostdlib option prevents the import of mscorlib.dll, which defines the entire System namespace. Use this option if you want to define or create your own System namespace and objects. This option is used by the SSCLI build system in order to bootstrap the build
of the base class libraries in mscorlib.dll. |
|
/noconfig | Prevents compilation with the global or local versions of csc.rsp.
The /noconfig option tells the compiler not to compile with the global or local
versions of csc.rsp. |
|
/nowarn:number1[,number2[...]] | Suppresses the compiler's ability to generate
specified warnings where number1 and number2 are warning numbers that you
want the compiler to suppress. The /nowarn option lets you suppress the
compiler's ability to generate one or more warnings. Separate multiple warning
numbers with a comma. |
|
/optimize[+ | -] | Enables or disables optimizations. The /optimize option
enables or disables optimizations performed by the compiler to make your output
file smaller, faster, and more efficient. /optimize also tells the common
language runtime to optimize code at runtime. |
|
/out:filename | Specifies the output file where filename is the
name of the output file created by the compiler.
The /out option specifies the name of the output file. The compiler expects
to find one or more source code files following the /out option.
On the command line, it is possible to specify multiple output files for your
compilation. All source code files specified after an /out option will be
compiled into the output file specified by that /out option. A source code file
used to compile one output file cannot be used in the same compilation to
compile another output file. |
|
/recurse:[dir\]file | Searches subdirectories for source files to compile
where dir (optional) is the directory in which you want the search to
begin and file is the file or files to search for. Wildcard characters are
allowed.
If dir is not specified, the search begins in the directory where the csc command was executed. The /recurse option lets you compile source code files in all child
directories of either the specified directory (dir) or the directory where the
csc command was executed. |
|
/reference:file[;file2]
|
Imports the information in the metadata of the
referenced assembly for use in resolving external references where file
and
file2 are one or more files containing an assembly manifest. To import
more than one file, separate file names with either a comma or a semicolon.
The /reference option causes the compiler to make public type information in
the specified files available to the project you are currently compiling.
Use /lib to specify the directory in which one or more of your assembly
references is located. The /lib topic also discusses which directories the
compiler searches for assemblies. |
|
/resource:filename[,identifier] | Embeds a .NET Framework resource into the output file
where filename is the SSCLI resource file you want to embed in the output
file and identifier (optional) is the logical name for the resource; the
name used in code to load the resource.
The default identifier is the file name. Use /linkresource to link a resource to an assembly rather than placing the
resource file in the output file. |
|
/target:output_type | Specifies the type of assembly to be generated by
the compiler. Unless you specify /target:module, /target causes assembly
metadata to be placed in an output file.
The compiler creates only one assembly manifest per compilation. Information
about all files in a compilation is placed in the assembly metadata. All output
files except those created with /target:module can contain an assembly manifest.
When producing multiple output files at the command line, only one assembly
manifest can be created and it must go into the first output file specified on
the command line. If the first output file is an executable assembly
(/target:exe or /target:winexe) or code library (/target:library), then any
other output files produced in the same compilation must be modules
(/target:module). Specify the format of the output file using one of four options: |
|
/target:exe | The /target:exe option causes the compiler to create an executable
(EXE), console application. The /target:exe option is in effect by default. The
executable file will be created with the .exe extension. Unless otherwise specified with the /out option, the output file name takes the name of the input file that contains the Main method. When specified at the command line, all files up to the next /out, /target:winexe, or /target:library option are used to create the .exe file. The /target:exe option is in effect for all files following the previous /out or /target:library option. One and only one Main method is required in the source code files that are compiled into an .exe file. The /main compiler option lets you specify which class contains the Main method, in cases where your code has more than one class with a Main method. |
|
/target:library | The /target:library option causes the compiler to create a
dynamic-link library (DLL) rather than an executable file (EXE). The DLL will be
created with the .dll extension. Unless otherwise specified with the /out option, the output file name takes the name of the first input file. When specified at the command line, all files up to the next /out, /target:winexe, or /target:exe option are used to create the .dll file. When building a .dll file, a Main method is not required. |
|
/target:module | To prevent generation of an assembly manifest, use the /target:module
option. By default, the output file will have a .netmodule extension. A file that does not have an assembly manifest cannot be directly loaded by the SSCLI execution engine. However, such a file can be incorporated into the assembly manifest of an assembly using the /addmodule option. If more than one module is created in a single compilation, internal types in one module will be available to other modules in the compilation. When code in one module references internal types in another module, then both modules must be incorporated into an assembly manifest, using /addmodule. |
|
/target:winexe | The /target:winexe option causes the compiler to create an
executable Windows GUI application. The executable file will be created
with the .exe extension. This sets the subsystem information in the PE file
that is used by Windows to determine some execution characteristics
of the application. This information is ignored by the SSCLI implementation of
the CLI. However, if the application is executed under the .NET
Framework this option will be significant. For more information on the
console or Windows subsystem setting see http://msdn.microsoft.com and search for
"console subsystem". |
|
/unsafe | Allows code that uses the unsafe keyword to compile. | |
/utf8output | Displays compiler output using UTF-8 encoding. In some international configurations, compiler output cannot correctly be displayed in the console. In these configurations, use /utf8output and redirect compiler output to a file. |
|
/warn:option | Specifies the warning level for the
compiler to display. Use /warnaserror to treat all warnings as errors. /w is the short form of /warn. option is the minimum warning level you want displayed for the build. Valid values are 0-4. |
|
Warning level | Meaning | |
0 | Turns off emission of all warning messages. | |
1 | Displays severe warning messages. | |
2 | Displays level 1 warnings plus certain, less-severe warnings, such as warnings about hiding class members. | |
3 | Displays level 2 warnings plus certain, less-severe warnings, such as warnings about expressions that always evaluate to true or false. | |
4 | Displays all level 3 warnings plus informational warnings. This is the default warning level at the command line. | |
/warnaserror[+ | -] | Promotes warnings to errors. The /warnaserror+
option treats all warnings as errors. Any messages that would ordinarily be
reported as warnings are instead reported as errors, and the build process is
halted (no output files are built). |
csc File.cs
csc /target:library File.cs
csc /out:My.exe File.cs
csc /define:DEBUG /optimize /out:File2.exe *.cs
csc /target:library /out:File2.dll /warn:0 /nologo /debug *.cs
csc /target:library /out:Something.xyz *.cs
Copyright (c) 2006 Microsoft Corporation. All rights reserved.