Get the App
SLTechnology News&Howtos  ›  Development  › 

How to configure the C # command line compiler

Shulou Source: shulou.com Published: 2022-06-02 14:01:09 10月02日 Update

This article mainly introduces how to configure the C # command line compiler, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to know it.

1. Configure the C# command line compiler:

My computer-> Advanced-> Environment variables-> Path-> add "; C:\ Windows\ Microsoft.NET\ Framework\ v2.0.50727" (a path version of Path

Change as a result of the change. The csc.exe (C # command line compiler) is placed in this directory. Through csc /? To view all the parameters.

two。 Configure other .NET command line tools

After configuring the C# command line compiler, you need to configure other command line tools. My computer-> Advanced-> Environment variables-> Path-> add "; D:\ Program Files\ Microsoft Visual Studio 8\ SDK\ v2.0\ Bin" (Path changes with the installation directory, if installed in C:\, it is "; C:\ Program Files\ Microsoft Visual Studio 8\ SDK\ v2.0\ Bin"

3. To compile the C # file through the csc command line compiler, here is an example

1) create a new text file named test.txt under disk D, enter the following text and save it as a test.cs file

/ / A simple C # application. UsingSystem; classTestApp {publicstaticvoidMain () {Console.WriteLine ("testament 1 and 2); Console.ReadKey ();}}"

2) run-> cmd-> D:\-> csc D:\ test.cs. After successful compilation, generate the test.exe executable file under disk D.

3) enter test.exe, enter, and display the result (Test! 1, 2, 2, 3)

4. Next, the Windows Forms program, test.cs, is generated by introducing the System.Windows.Forms namespace

Change it to the following and compile again

/ / A simple C # application. UsingSystem; / / be sure to add the following line: usingSystem.Windows.Forms; classTestApp {publicstaticvoidMain () {Console.WriteLine ("testament 1, Application 2, 3"); MessageBox.Show ("Hello...", "Application"); Console.ReadKey ();}}

5. Compile multiple source files using csc.exe

/ / HelloMessage.cs usingSystem; usingSystem.Windows.Forms; classHelloMessage {publicvoidSpeak () {MessageBox.Show ("Hello");}} / / Test.cs usingSystem; classTestApp {publicstaticvoidMain () {Console.WriteLine ("Testinghammer 1 ~ 2 ~ 3"); HelloMessageh=newHelloMessage (); h.Speak ();}}

Parameter / out: the location and name of the compilation result

Csc/out:e:\ a.exe test.cs HelloMessage.cs

Or compile all the cs files in the current directory: csc/out:e:\ a * cs

Thank you for reading this article carefully. I hope the article "how to configure the C# Command Line Compiler" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Compiling commands clips compilers configurations files articles directories programs advanced parameters variables tools applications text environment computer results applications generation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Linux Xiaomi vpn Redmi