1
1

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 5 years have passed since last update.

.NET で HelloWorld を Macでやってみた

Posted at

.NETをやる必要がなにやらありそうなので、Macで環境構築を行った時のメモ

.NET Core のインストール

.NET Core

brew でまずは最新の openssl をインストールするみたい

$brew update

$brew install openssl

$ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib

$ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/

次に最初のリンクから辿れる Official Installer よりインストール。
しかし、dotnet コマンドのパスが通っておらず使えない。
と思ったら、known Issueのページに oh-my-zsh 使うとこの問題があるよと書いてあった。

Known issues & workarounds

書いてある通り、シンボリックリンクを作成する。

$ln -s /usr/local/share/dotnet/dotnet /usr/local/bin

$dotnet --version
1.0.0-preview2-003121

よし。
書いてある通り、コマンドを実行。

$mkdir hwapp
$cd hwapp
$dotnet new

dotnet newコマンドでHello World用のファイルができるようだ。
Program.cs と project.json ができていた。
それぞれ以下の様な感じ。

Program.cs
using System;

namespace ConsoleApplication
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}
project.json
{
  "version": "1.0.0-*",
  "buildOptions": {
    "debugType": "portable",
    "emitEntryPoint": true
  },
  "dependencies": {},
  "frameworks": {
    "netcoreapp1.0": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.0.0"
        }
      },
      "imports": "dnxcore50"
    }
  }
}

次にdotnet restoreコマンドを実行。

$dotnet restore

これで project.lock.json というファイルできる。

次に実行。

$dotnet run
Project hwapp (.NETCoreApp,Version=v1.0) will be compiled because expected outputs are missing
Compiling hwapp for .NETCoreApp,Version=v1.0

Compilation succeeded.
    0 Warning(s)
    0 Error(s)

Time elapsed 00:00:01.4154838


Hello World!

Visual Studio Code をインストールする

Visual Studio Code

インストーラーがあるのでインストール。
インストールしたら起動。
拡張機能で C# をインストール。
先ほど開いたプロジェクトを開くことが出来て、編集出来たり。

1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?