'csc'未被识别为内部或外部命令,可操作程序或批处理文件

Cal*_*lat 10 c# cmd path environment-variables csc

我是C#的新手,我正在尝试使用cmd来编译一个名为的基本hello world文件test.cs.它包含以下内容:

// 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
     */
Run Code Online (Sandbox Code Playgroud)

当我尝试运行该行时,csc test.cs我得到以下输出: img的问题

Am_*_*ful 21

找到csc.exe的路径并将其添加到您的PATH环境变量中.

在我的例子中,64位C#编译器的路径是C:\Windows\Microsoft.NET\Framework64\v4.0.30319.

同样,您可以C:\Windows\Microsoft.NET\Framework在不同的.NET框架版本目录中查找32位C#编译器

所有版本都会有csc.exe,如v2.0.XXXXX和v3.5.根据您的要求,在Framework64/Framework目录中选择具有最高版本的版本.

复制csc.exe的路径并将其添加到PATH系统环境变量.

退出cmd,然后再次启动并运行该程序.那很有用.

  • 我如何将其添加到环境变量中?我是 cmd 的新手,所以我不知道那是什么 (2认同)
  • @KazRodgers - 检查此链接 -&gt; https://www.java.com/en/download/help/path.xml。它展示了如何为不同的操作系统编辑环境变量 `PATH`。严格按照步骤操作,因为您可能会犯一些错误。 (2认同)