Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 648
Callat Avatar asked Mar 28 '17 21:03

Callat


People also ask

How do you fix CSC is not recognized as an internal or external command?

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.

How do you fix is not recognized as an internal or external command operable program or batch file?

You can resolve this issue in three ways: First, use the full path of the executable file to launch the program. Second, add the program path to Windows environment variables. Finally, move the files to the System32 folder.

What is CSC in command prompt?

CSC.exe is the CSharp compiler included in the . NET Framework and can be used to compile from the command prompt. The output can be an executable ".exe", if you use "/target:exe", or a DLL; If you use /target:library, CSC.exe is found in the . NET Framework directory, e.g. for .

Where is csc.exe located?

The csc.exe executable file is usually located in the Microsoft.NET\Framework\<Version> folder under the Windows directory.


1 Answers

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.

like image 149
Am_I_Helpful Avatar answered Oct 23 '22 17:10

Am_I_Helpful