c# - 从命令行编译 C# 代码会出错

标签 c#

我正在学习本教程:

http://www.csharp-station.com/Tutorials/Lesson01.aspx

我将其粘贴到一个文本文件中,将其命名为 Welcome.cs:

// Namespace Declaration
using System;

// Program start class
class WelcomeCSS
{
    // Main begins program execution.
    static void Main()
    {
        // Write to console
        Console.WriteLine("Welcome to the C# Station Tutorial!"); 
    }
}

然后我进入命令提示符,指向文件的目录。我键入 csc.exe Welcome.cs 并收到此错误消息:

csc.exe is not recognized as internal or external command

我正在使用 Visual Studio 2008

我尝试将 csc.exe 移动到 Windows 目录,但现在出现此错误:

fatal error cs2018: unable to find messages file 'cscompui.dll'

如何从命令行编译我的 C# 代码?

最佳答案

csc.exe 不在您的路径中。尝试完全限定它:

C:\WINDOWS\Microsoft.NET\Framework\v3.5\csc.exe

(当然,用您正在使用的任何框架替换 3.5。)

请注意,此处未使用 Visual Studio。你使用的是什么版本并不重要,因为当你从命令行编译时你没有使用它。命令行编译器是框架本身的一部分。

关于c# - 从命令行编译 C# 代码会出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3425515/

相关文章:

c# - 是否可以将 Resharper Intellisense 配置为按字母顺序排序?

c# - LINQ - 选择一个对象的属性以供进一步使用,而不是在每个地方取消引用它

c# - 找不到提供程序 'System.Data.SQLite' 的 MigrationSqlGenerator

c# - 为 HttpRequestMessage.Properties 定义的字典键 "MS_HttpContext"在哪里?

C# 全局键和 SetForegroundWindow

c# - 在不保存到 UWP C# 文件的情况下在图像控件上显示 SoftwareBitmap

c# - 如何从 ASP.NET Web API 读取 XML?

c# - 您可以在不需要集成测试的情况下自行测试 razor View 吗?

c# - VALA 与 AOT 编译之间的性能差异?

c# - C#中使用HtmlAgilityPack解析网页信息