Csung command line editor csc.exe compiles the helloworld Program

Source: Internet
Author: User
Tags net command net command line line editor

1. Configure the C # command line compiler:

My computer-> advanced-> environment variable-> path-> Add "; C: \ WINDOWS \ Microsoft. net \ framework \ v2.0.50727 "(the last path of the path changes with the version ). Csc.exe (C # command line compiler) is placed in this directory. Through  /? To view all the parameters.

2. Configure other. Net command line tools

My computer-> advanced-> environment variable-> path-> Add "; D: \ ProgramFiles \ Microsoft Visual Studio 8 \ SDK \ V2.0 \ bin "(path changes with the installation directory. If it is installed in c: \, it is"; C: \ Program Files \ Microsoft Visual Studio 8 \ SDK \ V2.0 \ bin"

3. Basic command line knowledge
If you use the command line for a limited number of times, please let me explain some basic details for necessary preparation.

First, you can use a backslash or a single dashes to specify the csc.exe option. Second, it is illegal to have extra spaces between/or-and the subsequent sign. Therefore, "-help" is completely correct, and "-help" won't work. To illustrate this, let's use the help flag to check the complete command line option set:

-help
help

If everything is normal, you should see all possible signs.

Many options provide simplified notation to save you some time in typing. What is the abbreviated expression of the help Mark ?, You can list the options of csc.exe as follows:


Many options require additional modifiers, such as directory paths and file names. A flag of this nature uses a colon to separate the flag from its modifier. For example, the/reference option requires that the. NET Assembly name be included in the assembly list:

reference: mylibrary. dll...

Other flags are binary in nature because they are either enabled (+) or disabled (-). Binary flags are always disabled by default. Therefore, you only need to use the plus sign. For example, to treat all compilation warnings as errors, you can enable the warnaserror flag:

warnaserror +...

The order of the flag does not matter, but the set of all the flag must be listed before the set of input files is specified. It is also worth noting that it is illegal to have additional spaces between the modifier and its associated data. For example, use/reference: mylibrary. dll instead of/reference: mylibrary. dll.

 

4. C # common options for the command line compiler

(1)/addmodule

Specify the modules to be included in the created Assembly. This is an easy way to create a multi-file assembly.

(2)/debug

Debugging information can be generated.

(3)/define

Pre-processor commands can be directly transmitted to the compiler:/define: Debug

(4)/delaysign

Build an assembly using a strong-name delayed signature.

(5)/doc

Specify the output file containing the XML document to be generated.

(6)/Keyfile

Specifies the path of the. SNK file, which contains the key pair used for strong signature.

(7)/lib

Specifies the location of the Assembly contained in the/reference option.

(8)/out

The name of the output file, which is suffixed with .exe.

(9)/reference (Abbreviation/R)

Reference an external assembly.

(10)/Resource

Embed resource files into the created assembly.

(11)/target (Abbreviation/T)

Specify the type of the created output file:

/T: EXE build *. EXE console application, which is the default output

/T: Library Build *. dll assembly

/T: module build a module that does not contain a list (portable executable file, PE)

/T: winexe build *. EXE windows form assembly

 

The true meaning of using the original compiler is that it can process multiple files and programs at the same time.

For example, there are two C # source files: client. CS and clientlib. CS.

I: Compile multiple files:

C # The Compiler accepts multiple input source files and combines the output into an assembly.

out: client.exe client. CS clientlib. CS

II: creating and using code Libraries

The code in clientlib can be put into a separate library, which can be accessed by all customers

T: Library clientlib. CS

The output is an Assembly named clientlib. dll. Compile the Customer Code and reference this external assembly:

R: clientlib. dll client. CS

The output is an Assembly named client.exe. If you use ildasm to view the output, you can see that the List contains references to the lientlib assembly.

Iii. Create a multi-file assembly

Compared with a single program set, the better way is to pack clientlibas a single file to the client.exe program set. Since there is only one file in the program set that contains the list, you must first compile clientlib. cs into a portable executable module. To do this, set the output target to module:

T: module clientlib. CS

The output file is clientlib. netmodule. Use addmodule of the compiler to upload the certificate to the client.exe assembly:

addmodule: clientlib. netmodule client. CS

The Final Assembly contains two files: client.exe and clientlib. netmodule.

 

5. A simple example of compiling a C # file using the command line compiler

1. Create a New hello.txt text file on the D Drive. Enter the following text and save it as a hello. CS file.

Using system;

Class helloworld
{
Static void main ()
{
Console. writeline ("Hello world! ");
Console. readkey ();
}
}

2) Run-> cmd-> D: \-> csc d: \ hello. cs. After the compilation is successful, the hello.exe executable file is generated under the ddrive.

3rd, enter hello.exe and press Enter. The result is Hello world!

Reprinted Source: http://hi.baidu.com/jhtb/blog/item/95fb463ca2f83a0abaa16709.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.