2

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?

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
  • 1
    [_"The csc.exe executable file usually is located in the Microsoft.NET\Framework\Version folder under the Windows directory."_](https://msdn.microsoft.com/en-us/library/78f4aasd.aspx) – cbr Jul 11 '15 at 10:34
  • When you have a VS installed then there should be a "Visual Studio Command Prompt" too. It has those settings preconfigured. – H H Jul 11 '15 at 11:01
  • Possible duplicate of [Compiling/Executing a C# Source File in Command Prompt](https://stackoverflow.com/questions/553143/compiling-executing-a-c-sharp-source-file-in-command-prompt) – Stephen Kennedy Feb 18 '18 at 12:16

1 Answers1

3

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:

enter image description here

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.

codingadventures
  • 2,924
  • 2
  • 19
  • 36