• csc.exe编译C#文件


    通过C#命令行编译器编译C#文件
    1.配置C#命令行编译器: 我的电脑—高级—环境变量—〉Path —〉添加";C:WindowsMicrosoft.NETFrameworkv2.0.50727"(Path的最后一个路径虽版本的改变而改变)。
    csc.exe(C#命令行编译器)就放在该目录下。通过csc /?来查看所有参数。
    2.配置其它.NET命令行工具我的电脑—〉高级—〉环境变量—〉Path —〉添加";D:Program FilesMicrosoft Visual Studio 8SDKv2.0Bin"(Path
    随安装目录的改变而改变,如果安装在C:,则为";C:Program FilesMicrosoft Visual Studio 8SDKv2.0Bin"
    3.通过csc命令行编译器来编译C#文件,以下为一个例子
    1)在D盘下新建一个名为test.txt文本文件,输入以下文本后保存为test.cs文件
    //一个简单的C#应用程序. 
    using System; 
    class TestApp 
    { 
        public static void Main() 
        { 
            Console.WriteLine("Test! 1,2,3"); 
            Console.ReadKey(); 
        } 
    } 
    
    2)运行—〉cmd —〉D: —〉csc D:	est.cs, 编译成功后在D盘下生成test.exe可执行文件 
    
    3)输入test.exe,回车,显示结果(Test! 1,2,3) 
    
    4.接下来通过引入 System.Windows.Forms 命名空间来生成 Windows Forms 程序,
    test.cs修改为如下后再次编译
    //一个简单的C#应用程序. 
    
    using System; 
    //一定要加上下面一行
    using System.Windows.Forms;
    class TestApp 
    { 
        public static void Main() 
        { 
            Console.WriteLine("Test! 1,2,3"); 
            MessageBox.Show("Hello...","Application"); 
            Console.ReadKey(); 
        } 
    } 
    
    5.使用csc.exe编译多个源文件 
    
    //HelloMessage.cs 
    using System; 
    using System.Windows.Forms;
    class HelloMessage 
    { 
        public void Speak() 
        { 
            MessageBox.Show("Hello"); 
        } 
    } 
    
    //Test.cs 
    using System; 
    class TestApp 
    { 
        public static void Main() 
        { 
            Console.WriteLine("Testing! 1,2,3"); 
            HelloMessage h = new HelloMessage(); 
            h.Speak(); 
        } 
    }
    
    参数/out:编译结果的存放位置和名称
    csc/out:e:a.exe test.cs HelloMessage.cs 或者编译当前目录下的所有cs文件: csc/out:e:a *cs
  • 相关阅读:
    HDU 1813 Escape from Tetris
    BZOJ 2276 Temperature
    BZOJ 4499 线性函数
    BZOJ 3131 淘金
    HDU 5738 Eureka
    POJ 2409 Let it Bead
    POJ 1286 Necklace of Beads
    POJ 1696 Space Ant
    Fox And Jumping
    Recover the String
  • 原文地址:https://www.cnblogs.com/quke123/p/4101172.html
Copyright © 2020-2023  润新知