Visual Studio Code と Yeoman で asp.net 5 事始め
kawa.xxx
4/29 に行われた Build 2015 ディベロッパーカンファレンスにてWindows 以外でも動作する Visual Studio Code が発表されましたね!
本家Visual Studio の様に複雑な機能はなくテキストエディタに近い感じですが、IntelliSenseはバッチリ。そんな Visual Studio Code を Mac 上で使って asp.net 5 で hello world してみました。
環境
- OSX 10.10.3
- Visual Studio Code 0.1.0
- node.js 0.12.2
- Yeoman 1.4.6
- bower 1.4.1
- grunt 0.4.5
実施手順
- Visual Studio Code をダウンロードします。
- Docs の Setup にある通りに
.bashrc
等に code で Visual Studio Code を起動出来るスクリプトを追記します。 - node.js をインストールします。
- Yeoman, bower, grunt-cli を npm でインストールします。
$ npm instal yo bower grunt-cli
- asp.net 5 プロジェクトを生成するために
generator-aspnet
をインストールします。$ npm install generator-aspnet
- brew で asp.net をインストールします。
$ brew tap aspen/dnx $ brew update $ brew install dnvm
.bashrc
等に下記追記します。
export MONO_GAC_PREFIX=“/usr/local” source dnvm.sh
- プロジェクトをジェネレートします。
$ mkdir project $ cd project $ yo
下図の様にどんなプロジェクトを作るか聞かれるのでとりあえず、 Web Application
で生成します。
その後、プロジェクト名を聞かれるのでとりあえず helloworld とかで。
すると、rails の scaffolding の様につらつらとファイルが生成されます。
dnu restore
でパッケージ等を取得する。
初回は結構大量のものを取ってくるので大分ながい。
しかも途中で固まる可能性もあるので、固まったら Ctrl+c で止めてもう一回やり直してください。だいたい2回やればうまくいくはず。- Visual Studio Code でコードを眺めてみる
$ code .
それっぽいですね!
-
実行する
dnx . kestrel
-
確認する
localhost:5001
にアクセスする。- もし
IOException: kqueue() FileSystemWatcher has reached the maximum nunmber of files to watch.
が表示されるようだったら、.bashrc
等にexport MONO_MANAGED_WATCHER=false
を追記してください。既知のバグのようです。
感想
Rails とかと似たような感じで asp.net の開発が出来る!慣れている人はいいけれど、どっぷり Windows と Visual Studio な人にはちょっと取っ付きづらいかも。まぁ、本家 Visual Studio が使えるのであればそちらのほうがまだまだ効率いいですね。 R# もある環境ならなおさらですわ。
参考文献
- http://jp.techcrunch.com/2015/04/30/20150429microsoft-shocks-the-world-with-visual-studio-code-a-free-code-editor-for-os-x-linux-and-windows/
- http://channel9.msdn.com/Events/dotnetConf/2015/ASPNET-5-Project-Scaffolding-with-Yeoman
- http://www.itworld.com/article/2917266/development/how-to-install-and-use-visual-studio-code-and-aspnet-5-on-mac-os-x.html
ABOUT ME