LoginSignup
0
1

More than 3 years have passed since last update.

VSを使わずC#をコンパイルする方法

Last updated at Posted at 2020-09-18

検証環境

・Windows10 64bit 1909 build 18363.1082
・DotnetFramework x64 v4.0.30319

参考(というかほとんどパクリ…)

手順

①下記のサンプルcsファイルを作成

test.cs
using System;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Reflection;
using System.Windows.Forms;
using System.Drawing;

class Neko : Form {

  [STAThread]
  public static void Main() {
    GeneratedCodeAttribute generatedCodeAttribute = new GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator","10.0.0.0);
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run( new Neko());
  }

  Neko(){
    Text = "Button Click Sample";
    ClientSize = new Size(200, 200);
    Button btn1 = new Button();
    TextBox txb1 = new TextBox();
    Label lb1 = new Label();
    btn1.Location = new Point(50, 50);
    txb1.Location = new Point(100,100);
    lb1.Location = new Point(150,150);

    btn1.Text = "Click!";
    btn1.Click += btn1_Click;

    lb1.Text = "test";

    Controls.AddRange(new Control[] { btn1 });
    Controls.AddRange(new Control[] { txb1 });
    Controls.AddRange(new Control[] { lb1 });
  }

  void btn1_Click(object sender, System.EventArgs e) {
    MessageBox.Show("こんにちはにゃー", "挨拶");
  }
}

②コマンドプロントを起動し下記コードを実行

実行
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe D:\test\test.cs

③cmdのカレントディレクトリに"test.exe"が吐き出されるので実行する。
image.png

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1