0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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

###参考(というかほとんどパクリ…)
https://qiita.com/toshirot/items/dcf7809007730d835cfc

###手順
①下記のサンプル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
2
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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?