커맨드 라인에서 C# 프로그램을 컴파일할 수 있다.
굳이 Visual Studio를 사용하지 않아도 되기때문에 상당히 편리하다. 기본적으로 윈도우즈에 C# 컴파일러가 포함되어 있기 때문 인 것 같다.
컴파일 명령은 아래와 같다. 컴파일하고자 하는 프로그램이 test.cs 라 할 때의 경우이다.
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe test.cs <--- 순수 Console 프로그램인 경우 (1)
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe -target:winexe test.cs <--- button 등이 있는 경우 (2)
아래의 프로그램은 Microsoft에서 예제로 올려 놓은 것이다. 프로그램을 test.cs 로 저장하고 (2)의 방법으로
컴파일 해보자.
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace FormWithButton
{
public class Form1 : Form
{
public Button button1;
public Form1()
{
ClientSize = new Size(285, 85); // Set the form size
button1 = new Button();
button1.Size = new Size(40, 40);
button1.Location = new Point(30, 30);
button1.Text = "Click me"; this.Controls.Add(button1);
button1.Click += new EventHandler(button1_Click);
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("Hello World");
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new Form1());
}
}
}
'C# 언어' 카테고리의 다른 글
| C# 에서 List 추가 및 정렬하기 (0) | 2021.01.14 |
|---|---|
| C# 으로 시계 만들기 (2) (0) | 2021.01.11 |
| C# Timer 를 이용해서 시계 만들기 (0) | 2021.01.10 |
| C# 윈도우즈 폼을 사용하여 Hello world 출력하기 (1) | 2021.01.01 |
| C#을 사용하여 계산기 만들기 (0) | 2020.11.19 |
댓글