简体   繁体   中英

I want to compile a C# file using command prompt

I wrote a simple C# file. When I compile it using command prompt, I get an error

'csc' is not recognized as an internal or external command, operable program or batch file.

Do I need to set an environment variable?

When you install Visual Studio it comes with it a batch file that sets up the environment for you and opens a cmd window. It's called Developer Command Prompt for VS201x (where x is the Visual Studio version you have). It is located in the Visual Studio Tools menu, usually at:

C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Visual Studio 201x\Visual Studio Tools

This is the result:

在此输入图像描述

EDIT:

If you don't have Visual Studio installed you can still access the C# compiler shipped with the .NET Framework in Windows 8. You will find it in:

C:\Windows\Microsoft.NET\Framework\v4.0.30319

Otherwise you can install it manually. Here is the link

What you need to do after is just adding it to your environment variable path

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM