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

49,778

Locate the path of csc.exe and add it your PATH environment variable.

In my case, the path for 64-bit C# compiler is C:\Windows\Microsoft.NET\Framework64\v4.0.30319.

Similarly, you can look for 32-bit C# compiler in C:\Windows\Microsoft.NET\Framework under different .NET framework version directories

There will be csc.exe for all versions like v2.0.XXXXX and v3.5. Select the one with the highest version in Framework64/Framework directory depending on your requirement.

Copy the path of csc.exe and add it to the PATH system environment variable.

Quit the cmd, and then launch again and run the program. That'd work.

Share:
49,778

Related videos on Youtube

Callat
Author by

Callat

I'm your avg nerd and new programmer I'm out to learn new software so that when the machines take over the world, I can take over the machine. "Knowledge is not enough, one must apply" Bruce Lee

Updated on July 09, 2022

Comments

  • Callat
    Callat almost 2 years

    I'm fairly new to C# and I'm trying to use cmd to compile a basic hello world file called test.cs. It contains the following:

    // Similar to #include<foo.h> in C++, includes system namespaces in a program
    
        using System;
        using System.Collections.Generic;
        using System.Linq;
        using System.Text;
        using System.Threading.Tasks;
    
        // A name space declaration, a class is a group of namespaces
        namespace Program1
        {
            class Hello // my class here, classes can contain multiple functions called methods which define it's behavior
            {
                static void Main(string[] args) // main method, just like in C/C++ it's the starting point for execution cycle
                {
                    Console.WriteLine("Hello World");
                    Console.ReadKey(); // similar to _getch() in C++ waits for user to input something before closing
                }
            }
        }
    
        /*
         * Other notes, .cs is a c# file extension
         * cs files can be built via terminal by using csc foo.cs to generate foo.exe run it with foo
         */
    

    When I try to run the line csc test.cs I get the following output: img of issue

    • Gonzalo.-
      Gonzalo.- about 7 years
      is csc part of your environment variables? probably the compiler is not in your desktop (see the route in which you're executing the command). You might want to search where the compiler is and run it from there
    • Callat
      Callat about 7 years
      how would i find my environment variables? I'm a little familiar with terminal on ubuntu but I'm new to cmd
    • Mofi
      Mofi about 7 years
      Run "%SystemRoot%\Microsoft.NET\Framework64\v4.0.30319\csc.exe" test.cs instead of just csc test.cs, i.e. executable csc with file extension and with full path enclosed in double quotes to always work. The path depends on which .NET framework you want to use for compilation.
  • Callat
    Callat about 7 years
    how would i add that to an environment variable? I'm brand new to cmd so I don't know what that is
  • Am_I_Helpful
    Am_I_Helpful about 7 years
    @KazRodgers - Check this link -> java.com/en/download/help/path.xml. It shows how to edit environment variable PATH for different OS. Follow the steps very closely as you may commit some mistake.
  • Pavindu
    Pavindu about 5 years
    This compiler doesn't work for c sharp after version 5.
  • Marvin
    Marvin about 4 years
    Do we include the csc.exe in the path value?
  • Am_I_Helpful
    Am_I_Helpful about 4 years
    @Marvin - No, we don't include the exe name in the path value, only up to the directory inside which the executable needs to be searched.