Step
- Install .Net Core
- Install VSCode
- Install mono
- Create new project
- Restore project
- Create C# script
- Compile C# script
- Run binary
Step 1: Install .Net Core
- 公式の通りにやるだけ
- shellを開いていたら再起動する方がいいかもしれない
Step 2: Install VSCode
- ダウンロードするだけ
- Microsoft製のC# Extensionを入れる
Step 3: Install mono
brew update && brew install mono
Step 4: Create new project
cd ProjectDirctory && dotnet new
Step 5: Restore project
dotnet restore
Step 6: Create C# script
cmd.cs
using System;
namespace Example
{
class Cmd
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
}
}
}
Step 7: Compile C# script
mcs cmd.cs
Step 8: Run binary
mono cmd.exe
Complete!
Appendix
複数のファイルをCompileする
hello.cs
namespace Example
{
internal class Hello
{
internal string say()
{
return "Hello";
}
}
}
world.cs
namespace Example
{
internal class World
{
internal string say()
{
return "World";
}
}
}
cmd.cs
using System;
namespace Example
{
class Cmd
{
static void Main(string[] args)
{
Hello hello = new Hello();
World world = new World();
string h = hello.say();
string w = world.say();
var helloWorld = new []{ h, w };
var msg = string.Join(", ", helloWorld);
Console.WriteLine(msg);
}
}
}
mcs -out:cmd.exe -t:exe hello.cs world.cs cmd.cs
mono cmd.exe
Complete!