명령 프롬프트에서 C # 소스 파일 컴파일 / 실행
명령 프롬프트 창에서 .cs 파일을 어떻게 컴파일하고 실행합니까?
CSC.exe는 .NET Framework에 포함 된 CSharp 컴파일러이며 명령 프롬프트에서 컴파일하는 데 사용할 수 있습니다. / target : exe를 사용하면 출력이 실행 파일 (.exe)이거나 / target : library를 사용하면 DLL이 출력 될 수 있습니다. CSC.exe는 .NET Framework 디렉토리 (예 : .NET 3.5,)에 c:\windows\Microsoft.NET\Framework\v3.5\있습니다.
실행하려면 먼저 명령 프롬프트를 엽니 다 (시작 ...을 클릭 한 다음 입력 cmd.exe). 그런 다음 소스 파일이 들어있는 디렉토리로 cd해야 할 수도 있습니다.
다음과 같이 C # 컴파일러를 실행하십시오.
c:\windows\Microsoft.NET\Framework\v3.5\bin\csc.exe
/t:exe /out:MyApplication.exe MyApplication.cs ...
(한 줄에 모두)
컴파일 할 소스 모듈이 두 개 이상인 경우 동일한 명령 줄에 넣을 수 있습니다. 참조 할 다른 어셈블리가있는 경우을 사용하십시오 /r:AssemblyName.dll.
"entry point"역할을 할 클래스 중 하나에 정적 Main () 메소드가 정의되어 있는지 확인하십시오.
결과 EXE를 실행하려면 명령 프롬프트에 MyApplication다음을 입력 <ENTER>하십시오.
MSDN에 대한 이 기사에서는 명령 줄 컴파일러의 옵션에 대해 자세히 설명합니다. 리소스를 포함하고 아이콘을 설정하며 어셈블리에 서명 할 수 있습니다. Visual Studio 내에서 할 수있는 모든 작업이 가능합니다.
Visual Studio가 설치되어 있으면 시작 메뉴 (Visual Studio 도구 아래)에서 명령 줄 컴파일에 필요한 모든 환경 및 경로 변수를 설정하는 "Visual Studio 명령 프롬프트"를 열 수 있습니다.
이것을 아는 것이 매우 편리하지만 NAnt , MSBuild , FinalBuilder 등과 같은 일종의 빌드 툴에 대한 지식과 결합해야합니다 .이 툴은 기본 컴파일러뿐만 아니라 완벽한 빌드 환경을 제공합니다.
Mac에서
Mac에서는 구문이 비슷하며 C sharp Compiler 만 이름이 csc다음과 같습니다.
$ csc /target:exe /out:MyApplication.exe MyApplication.cs ...
그런 다음 실행하십시오.
$ mono MyApplication.exe
Visual Studio를 사용하지 않거나 설치하지 않고 C # 프로그램을 컴파일하는 다른 방법 은 환경 변수 (예 : "PATH")에 사용자 변수를 만드는 것입니다.
이 변수에 다음 경로를 복사하십시오.
"C : \ Windows \ Microsoft.NET \ 프레임 워크 \ v4.0.30319"
또는 PC의 .NET에 따라 다릅니다.
따라서 코드를 컴파일 할 때마다 전체 경로를 언급 할 필요가 없습니다. 간단히 사용
"C : \ Users \ UserName \ Desktop> csc [옵션] filename.cs"
또는 코드 경로가 어디에 있든지.
이제 잘 가십시오.
C # 프로그램을 컴파일 할 수 있습니다.
c :> csc Hello.cs
당신은 프로그램을 실행할 수 있습니다
c :> 안녕하세요
커맨드 라인에서 빌드하는 방법을 아는 것은 확실히 좋은 일이지만 대부분의 작업에서는 IDE를 사용하는 것이 더 쉬울 수 있습니다. C # Express Edition 은 무료이며 돈을 위해 아주 좋습니다 ;-p
또는 snippy 와 같은 것을 사용하여 C # 코드 조각을 실행할 수 있습니다.
마지막으로 명령 행은 구현에 따라 다릅니다. MS의 경우는 다음과 같습니다 csc. 대한 모노 , 그 것이다 gmcs모노에 대해 일반적으로 "모노 EXENAME"는 MS의 버전에 그냥 "EXENAME"하지만 : 친구는 .... 마찬가지로, 실행.
마지막으로 많은 프로젝트가 빌드 스크립트 도구로 빌드됩니다. MSBuild , NAnt 등
최신 .Net Framework 4.7에 더 이상 번들로 제공되지 않는 독립형 C # 7.0 컴파일러로 MSBuild를 설치하는 방법은 다음과 같습니다.
Visual Studio없이 C # 컴파일러를 설치할 수 있습니까?
그런 다음 실행
"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\Roslyn\csc.exe" MyApplication.cs
단일 소스 파일을 실행 파일로 컴파일합니다.
또한 .Net Core 는 사전 구성된 프로젝트없이 단일 소스 파일 컴파일을 지원하지 않습니다 .
LinqPad는 C # 코드를 무료로 테스트하는 빠른 방법입니다.
최신 버전의 경우 먼저 Powershell 창을 열고 임의의 폴더 (예 :)로 이동 c:\projects\하여 다음을 실행하십시오.
# Get nuget.exe command line
wget https://dist.nuget.org/win-x86-commandline/latest/nuget.exe -OutFile nuget.exe
# Download the C# Roslyn compiler (just a few megs, no need to 'install')
.\nuget.exe install Microsoft.Net.Compilers
# Compiler, meet code
.\Microsoft.Net.Compilers.1.3.2\tools\csc.exe .\HelloWorld.cs
# Run it
.\HelloWorld.exe
HelloWorld.cs의 예
using System;
public class HelloWorld {
public static void Main()
{
Console.WriteLine("Hello world!");
}
}
새로운 C # 인터프리터를 사용해 볼 수도 있습니다.)
.\Microsoft.Net.Compilers.1.3.2\tools\csi.exe
> Console.WriteLine("Hello world!");
Hello world!
You can build your class files within the VS Command prompt (so that all required environment variables are loaded), not the default Windows command window.
To know more about command line building with csc.exe (the compiler), see this article.
Once you write the c# code and save it. You can use the command prompt to execute it just like the other code.
In command prompt you enter the directory your file is in and type
To Compile:
mcs yourfilename.cs
To Execute:
mono yourfilename.exe
if you want your .exe file to be different with a different name, type
To Compile:
mcs yourfilename.cs -out:anyname.exe
To Execute:
mono anyname.exe
This should help!
In Windows systems, use the command csc <filname>.cs in the command prompt while the current directory is in Microsoft Visual Studio\<Year>\<Version>
There are two ways:
Using the command prompt:
- Start --> Command Prompt
- Change the directory to Visual Studio folder, using the command: cd C:\Program Files (x86)\Microsoft Visual Studio\2017\ <Version>
- Use the command: csc /.cs
Using Developer Command Prompt :
Start --> Developer Command Prompt for VS 2017 (Here the directory is already set to Visual Studio folder)
Use the command: csc /.cs
Hope it helps!
If you have installed Visual Studio then you have Developer Command Prompt for VS. You can easily build your program using csc command and run your application with the name of the application inside the developer command prompt.
You can open Developer command prompt as given below.
Start => Developer Command Prompt for VS
Hope this helps!
'Programming' 카테고리의 다른 글
| Unix 타임 스탬프 '120314170138Z'에서 'Z'는 무엇을 의미합니까? (0) | 2020.06.24 |
|---|---|
| Vim : let과 set의 차이점은 무엇입니까? (0) | 2020.06.24 |
| 파이썬에서 repr () 함수 이해 (0) | 2020.06.24 |
| Excel 셀에 그림 삽입 (0) | 2020.06.24 |
| RSpec vs Cucumber (RSpec 스토리) (0) | 2020.06.24 |