終於有時間在 Mac 上安裝一下 ASP.NET 5,網上有許多教程,可是多數的時間比較早了,版本不是最新,搭着 Build 2015 的春風,我也實踐一下 Mac OS X 上的 ASP.NET 5。css
常常使用 Windows 8.1,對 Mac 並不太熟悉,也一併把安裝中的問題趟一遍。html
前幾天剛剛更新了 Mac 的操做系統,操做系統版本 Mac OS X Yosemite 10.10.3。node
ASP.NET 5 運行在 DNX 之上,DNX 是 .NET 運行環境 ( .NET Execution Environment ) 的簡寫,它支持多種平臺,固然包括咱們今天的 OS X 了,在 OS X 上,使用 Homebrew 能夠很容易安裝 DNX。jquery
什麼是 Homebrew? 咱們先看看它。git
Homebrew 是用來在 Mac OS X 安裝 Linux 工具包最簡單和靈活的方式。官方網址:http://brew.sh。github
打開 Mac OS 的終端,輸入 ruby 命令web
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
就能夠了。安裝以後能夠檢查是否安裝成功。shell
brew –v
Homebrew 0.9.5
我如今的版本是 0.9.5npm
又一個新的縮寫詞 DNVM,英文的原文是 .NET Version Manager,就是 .NET 版本管理器,包含更新和配置 .NET 運行環境 ( KRE ) 所使用的一系列工具,是 ASP.NET 5 項目的一個子項目。DNVM 的網址:https://github.com/aspnet/dnvm/json
一旦成功安裝了 Homebrew,就可使用 brew 命令來安裝這個 DNVM。
brew 本身有默認的倉庫,使用 tap 能夠添加第三方的倉庫,咱們的 DNVM 就須要設置一下所在的倉庫。
在終端窗口中,使用下面的命令來設置這個第三方的倉庫。
brew tap aspnet/dnx
若是你想更新一下這個倉庫,可使用下面的命令先刪除原來的,再從新安裝,實現更新的目的。
brew untap aspnet/dnx brew tap aspnet/dnx
更新以後,才能夠安裝咱們真正須要的 DNVM。如今,能夠安裝 .NET 版本管理器了。
在終端中輸入下面的命令,安裝 DNVM。注意大小寫,命令中但是小寫的。這將會自動從 https://www.nuget.org/api/v2 安裝最新的 DNX 包。
brew install dnvm
終端中的輸出以下所示。
成功安裝以後,能夠在終端窗口中執行 dnvm 命令來檢查一下。
dnvm
應該看到以下的輸出。
___ _ ___ ____ ___ / _ \/ |/ / | / / |/ / / // / /| |/ / /|_/ / /____/_/|_/ |___/_/ /_/ .NET Version Manager - Version 1.0.0-beta5-10374 By Microsoft Open Technologies, Inc. DNVM can be used to download versions of the .NET Execution Environment and manage which version you are using. You can control the URL of the stable and unstable channel by setting the DNX_FEED and DNX_UNSTABLE_FEED variables. Current feed settings: Default Stable: https://www.nuget.org/api/v2 Default Unstable: https://www.myget.org/F/aspnetvnext/api/v2 Current Stable Override: <none> Current Unstable Override: <none> Use dnvm [help|-h|-help|--help] to display help text.
若是你看到的是
-bash: dnvm: command not found
也沒有關係,這是由於沒有找到 dnvm 這個命令而已,將 dnvm.sh 加入搜索路徑就能夠,這能夠經過下面的命令來實現。
source dnvm.sh
若是須要更新 DNX,那麼,可使用 upgrade 命令。
dnvm upgrade
如今,你的 DNX 就已經成功安裝了。使用 dnvm list 能夠查看全部的版本。
Active Version Runtime Arch Location Alias ------ ------- ------- ---- -------- ----- 1.0.0-beta5-11682 coreclr x64 ~/.dnx/runtimes * 1.0.0-beta4 mono ~/.dnx/runtimes default 1.0.0-beta5-11682 mono ~/.dnx/runtimes
能夠切換當前使用的 .NET 版本。
localhost:helloClr $ dnvm alias default 1.0.0-beta5-11682 Updating alias 'default' to 'dnx-mono.1.0.0-beta5-11682'
從新顯示一下當前的版本。
ocalhost:helloClr $ dnvm list Active Version Runtime Arch Location Alias ------ ------- ------- ---- -------- ----- 1.0.0-beta5-11682 coreclr x64 ~/.dnx/runtimes * 1.0.0-beta4 mono ~/.dnx/runtimes 1.0.0-beta5-11682 mono ~/.dnx/runtimes default
當關閉如今的終端窗口以後,從新打開終端窗口就會發現 dnx 很差用了。這是由於咱們使用 source 設置的路徑只能在當前的終端窗口中才能使用,若是但願可以保存下來,須要修改配置文件了。
查找一下 dnvm.sh 所在的文件夾。
localhost:~ $ mdfind -name dnvm.sh /usr/local/Cellar/dnvm/1.0.0-dev/libexec/dnvm.sh
環境建立以後,咱們通常都會建立一個控制檯的 Hello, world 程序來爽一把,程序就不用說了,主要是環境。
在桌面上建立了一個測試使用的文件夾 helloClr。在這裏面建立下面的兩個文件。
使用你喜歡的編輯器寫一個 helloworld.cs 程序,其實與 Windows 下固然是一摸同樣了。
using System; public class Program { public static void Main() { Console.WriteLine("Hello from DNX!"); } }
不同的是須要爲咱們這個簡單的項目,建立一個項目文件,文件名必須是 project.json,是 json 格式呀,不要寫錯了。在與 helloworld.cs 相同的文件夾下,建立這個 project.json 文件。內容以下。
{ "dependencies": { }, "frameworks": { "dnx451": {}, "dnxcore50": { "dependencies": { "System.Console": "4.0.0-beta-22605" }
} }
}
如今已經一切都準備好了,注意當前目錄須要在這個文件夾下,在終端窗口中,輸入運行的命令就能夠了。
dnx . run
沒有問題的話,就應該看到輸出的 Hello from DNX! 了。
在 Mac OS X 下面,還能夠設置一個環境變量 DNX_TRACE 來看看詳細的輸出。
export DNX_TRACE=1
如今的輸出豐富多了。
Information: [DefaultHost]: Project path: /Users/haogj/Desktop/helloClr Information: [DefaultHost]: Project root: /Users/haogj/Desktop/helloClr Information: [DefaultHost]: Packages path: /Users/haogj/.dnx/packages Information: [Breadcrumbs] Breadcrumbs for servicing will not be written because the breadcrumbs folder () does not exist. Information: [DependencyWalker]: Walking dependency graph for 'helloClr DNX,Version=v4.5.1'. Information: [WalkContext]: Graph walk stage 1 took in 9ms Information: [DependencyWalker]: Graph walk took 17ms. Information: [WalkContext]: Populate took 7ms Information: [DependencyWalker]: Resolved dependencies for helloClr in 26ms Information: [LoaderContainer]: Load name=helloClr Information: [ProjectLibraryExportProvider]: GetLibraryExport(helloClr, DNX,Version=v4.5.1, Debug, ) Information: [Microsoft.Framework.Runtime.Roslyn.RoslynProjectReferenceProvider]: GetProjectReference(helloClr, DNX,Version=v4.5.1, Debug, ) Information: [ProjectExportProviderHelper]: Resolving references for 'helloClr' Information: [ProjectExportProviderHelper]: Resolved 4 references for 'helloClr' in 6ms Information: [RoslynCompiler]: Compiling 'helloClr' Information: [LoaderContainer]: Load name=System.Security.Cryptography.Hashing Information: [LoaderContainer]: Load name=System.Security.Cryptography.Hashing.Algorithms Information: [RoslynCompiler]: Compiled 'helloClr' in 373ms Information: [CompilationContext]: Generating resources for helloClr Information: [CompilationContext]: Generated resources for helloClr in 3ms Information: [RoslynProjectReference]: Emitting assembly for helloClr Warning: PDB generation is not supported on this platform Information: [RoslynProjectReference]: Emitted helloClr in 827ms Information: [ProjectAssemblyLoader]: Loaded name=helloClr in 1240ms Hello from DNX!
查看一下當前目錄,能夠看到咱們熟悉的 helloworld.exe 文件,固然了,它必須使用 dnx 才能執行,能夠這樣直接執行程序。
dnx helloworld.exe
激動人心的時刻快到了,可是,咱們還須要作一些準備工做。
先確認一下你的 .NET 版本。還記得下面的命令嗎?檢查默認的版本。
dnvm list
Yeoman 是一個建立項目框架的應用,使用它咱們能夠建立出網站項目的基本框架。
默認的網站須要不少文件組成,包括樣式、腳本、配置等等,在 Mac 下面可沒有強大的 Visual Studio,這裏須要經過 Yeoman 來搭建基本的網站框架。
yeoman 須要經過 npm 來安裝,若是你已經安裝過 nodejs ,就已經安裝過它了,若是沒有,就先安裝 nodejs 吧。
因爲 npm 服務器在國外,國內使用起來問題較多,淘寶提供了一個國內鏡像,保障了安裝網絡環境的穩定,和源地址10分鐘同步一次,沒有被收錄的包會自動切換到npm官方下載,並添加進鏡像庫。說明連接地址:http://ju.outofmemory.cn/entry/118659
臨時使用淘寶 npm 庫,可使用以下命令
npm --registry https://registry.npm.taobao.org info underscore
安裝了 npm 以後,就可使用 install 命令來安裝 yeoman 了。
sudo npm install -g yo
安裝的輸出以下。
/usr/local/bin/yo -> /usr/local/lib/node_modules/yo/lib/cli.js > yo@1.4.6 postinstall /usr/local/lib/node_modules/yo > yodoctor Yeoman Doctor Running sanity checks on your system ✔ Global configuration file is valid ✔ NODE_PATH matches the npm root ✔ No .bowerrc file in home directory ✔ No .yo-rc.json file in home directory Everything looks all right! yo@1.4.6 /usr/local/lib/node_modules/yo ├── array-uniq@1.0.2 ├── figures@1.3.5 ├── titleize@1.0.0 ├── user-home@1.1.1 ├── opn@1.0.2 ├── humanize-string@1.0.1 (decamelize@1.0.0) ├── sort-on@1.2.0 (dot-prop@2.0.0) ├── yeoman-character@1.0.1 (supports-color@1.3.1) ├── async@0.9.0 ├── string-length@1.0.0 (strip-ansi@2.0.1) ├── root-check@1.0.0 (sudo-block@1.2.0, downgrade-root@1.1.0) ├── cross-spawn@0.2.9 (lru-cache@2.6.2) ├── chalk@1.0.0 (escape-string-regexp@1.0.3, ansi-styles@2.0.1, supports-color@1.3.1, strip-ansi@2.0.1, has-ansi@1.0.3) ├── findup@0.1.5 (commander@2.1.0, colors@0.6.2) ├── yosay@1.0.3 (ansi-regex@1.1.1, ansi-styles@2.0.1, word-wrap@1.0.3, strip-ansi@2.0.1, pad-component@0.0.1, taketalk@1.0.0, minimist@1.1.1) ├── meow@3.1.0 (object-assign@2.0.0, camelcase-keys@1.0.0, minimist@1.1.1, indent-string@1.2.1) ├── package-json@1.1.0 (registry-url@3.0.3) ├── npm-keyword@1.1.1 (registry-url@3.0.3) ├── update-notifier@0.3.2 (is-npm@1.0.0, latest-version@1.0.0, semver-diff@2.0.0) ├── got@2.9.2 (lowercase-keys@1.0.0, is-stream@1.0.1, timed-out@2.0.0, object-assign@2.0.0, prepend-http@1.0.1, nested-error-stacks@1.0.0, statuses@1.2.1, infinity-agent@2.0.3, duplexify@3.3.0, read-all-stream@2.1.2) ├── fullname@1.1.0 (npmconf@2.1.1) ├── yeoman-environment@1.2.5 (escape-string-regexp@1.0.3, untildify@2.0.0, log-symbols@1.0.2, diff@1.4.0, text-table@0.2.0, debug@2.2.0, mem-fs@1.1.0, globby@1.2.0, grouped-queue@0.3.0) ├── configstore@0.3.2 (object-assign@2.0.0, xdg-basedir@1.0.1, osenv@0.1.0, graceful-fs@3.0.6, uuid@2.0.1, mkdirp@0.5.0, js-yaml@3.3.0) ├── insight@0.5.3 (object-assign@2.0.0, lodash.debounce@3.0.3, os-name@1.0.3, tough-cookie@0.12.1, request@2.55.0) ├── lodash@3.8.0 ├── yeoman-doctor@1.3.2 (object-values@1.0.0, log-symbols@1.0.2, each-async@1.1.1, twig@0.7.2) └── inquirer@0.8.3 (ansi-regex@1.1.1, cli-width@1.0.1, through@2.3.7, readline2@0.1.1, rx@2.5.2)
安裝 yeoman 以後,還須要安裝 aspnet 的模版庫。使用下面的命令
sudo npm install -g yo generator-aspnet
輸出以下內容。
/usr/local/bin/yo -> /usr/local/lib/node_modules/yo/lib/cli.js > yo@1.4.6 postinstall /usr/local/lib/node_modules/yo > yodoctor Yeoman Doctor Running sanity checks on your system ✔ Global configuration file is valid ✔ NODE_PATH matches the npm root ✔ No .bowerrc file in home directory ✔ No .yo-rc.json file in home directory Everything looks all right! yo@1.4.6 /usr/local/lib/node_modules/yo ├── titleize@1.0.0 ├── array-uniq@1.0.2 ├── figures@1.3.5 ├── user-home@1.1.1 ├── opn@1.0.2 ├── humanize-string@1.0.1 (decamelize@1.0.0) ├── sort-on@1.2.0 (dot-prop@2.0.0) ├── yeoman-character@1.0.1 (supports-color@1.3.1) ├── async@0.9.0 ├── string-length@1.0.0 (strip-ansi@2.0.1) ├── cross-spawn@0.2.9 (lru-cache@2.6.2) ├── chalk@1.0.0 (escape-string-regexp@1.0.3, ansi-styles@2.0.1, supports-color@1.3.1, strip-ansi@2.0.1, has-ansi@1.0.3) ├── root-check@1.0.0 (sudo-block@1.2.0, downgrade-root@1.1.0) ├── findup@0.1.5 (commander@2.1.0, colors@0.6.2) ├── yosay@1.0.3 (ansi-regex@1.1.1, ansi-styles@2.0.1, word-wrap@1.0.3, strip-ansi@2.0.1, pad-component@0.0.1, taketalk@1.0.0, minimist@1.1.1) ├── meow@3.1.0 (object-assign@2.0.0, camelcase-keys@1.0.0, minimist@1.1.1, indent-string@1.2.1) ├── npm-keyword@1.1.1 (registry-url@3.0.3) ├── package-json@1.1.0 (registry-url@3.0.3) ├── update-notifier@0.3.2 (is-npm@1.0.0, latest-version@1.0.0, semver-diff@2.0.0) ├── got@2.9.2 (lowercase-keys@1.0.0, is-stream@1.0.1, timed-out@2.0.0, object-assign@2.0.0, prepend-http@1.0.1, nested-error-stacks@1.0.0, statuses@1.2.1, infinity-agent@2.0.3, read-all-stream@2.1.2, duplexify@3.3.0) ├── fullname@1.1.0 (npmconf@2.1.1) ├── configstore@0.3.2 (object-assign@2.0.0, xdg-basedir@1.0.1, osenv@0.1.0, graceful-fs@3.0.6, uuid@2.0.1, mkdirp@0.5.0, js-yaml@3.3.0) ├── yeoman-environment@1.2.5 (untildify@2.0.0, log-symbols@1.0.2, escape-string-regexp@1.0.3, diff@1.4.0, text-table@0.2.0, debug@2.2.0, mem-fs@1.1.0, globby@1.2.0, grouped-queue@0.3.0) ├── insight@0.5.3 (object-assign@2.0.0, lodash.debounce@3.0.3, os-name@1.0.3, tough-cookie@0.12.1, request@2.55.0) ├── lodash@3.8.0 ├── yeoman-doctor@1.3.2 (object-values@1.0.0, log-symbols@1.0.2, each-async@1.1.1, twig@0.7.2) └── inquirer@0.8.3 (ansi-regex@1.1.1, cli-width@1.0.1, through@2.3.7, readline2@0.1.1, rx@2.5.2) generator-aspnet@0.0.34 /usr/local/lib/node_modules/generator-aspnet ├── uuid@2.0.1 ├── chalk@1.0.0 (escape-string-regexp@1.0.3, ansi-styles@2.0.1, supports-color@1.3.1, strip-ansi@2.0.1, has-ansi@1.0.3) ├── yosay@1.0.3 (string-length@1.0.0, word-wrap@1.0.3, strip-ansi@2.0.1, ansi-regex@1.1.1, ansi-styles@2.0.1, pad-component@0.0.1, taketalk@1.0.0, minimist@1.1.1) ├── chai@1.10.0 (assertion-error@1.0.0, deep-eql@0.1.3) └── yeoman-generator@0.19.2 (read-chunk@1.0.1, detect-conflict@1.0.0, dargs@4.0.0, yeoman-welcome@1.0.1, xdg-basedir@1.0.1, user-home@1.1.1, diff@1.4.0, text-table@0.2.0, mime@1.3.4, async@0.9.0, istextorbinary@1.0.2, nopt@3.0.1, debug@2.2.0, run-async@0.1.0, cross-spawn@0.2.9, mem-fs-editor@1.2.3, mkdirp@0.5.0, shelljs@0.4.0, through2@0.6.5, cli-table@0.3.1, pretty-bytes@1.0.4, dateformat@1.0.11, underscore.string@3.0.3, glob@5.0.5, github-username@1.1.1, findup-sync@0.2.1, rimraf@2.3.3, class-extend@0.1.1, yeoman-assert@1.0.0, html-wiring@1.1.0, yeoman-environment@1.2.5, sinon@1.14.1, gruntfile-editor@1.0.0, lodash@3.8.0, download@4.1.2, inquirer@0.8.3)
安裝好生成器以後,咱們終於能夠建立一個網站項目了。直接在命令行輸入 yo 或者直接輸入 yo aspnet 就能夠了。有嚮導的呀。
? 'Allo OpenXLive! What would you like to do? Aspnet Make sure you are in the directory you want to scaffold into. This generator can also be run with: yo aspnet _-----_ | | .--------------------------. |--(o)--| | Welcome to the | `---------´ | marvellous ASP.NET 5 | ( _´U`_ ) | generator! | /___A___\ '--------------------------' | ~ | __'.___.'__ ´ ` |° ´ Y ` ? What type of application do you want to create? Web Application ? What's the name of your ASP.NET application? WebApplication create WebApplication/.gitgnore create WebApplication/Startup.cs create WebApplication/bower.json create WebApplication/config.json create WebApplication/MessageService.cs create WebApplication/project.json create WebApplication/package.json create WebApplication/gruntfile.js create WebApplication/Models/AccountViewModels.cs create WebApplication/Models/IdentityModels.cs create WebApplication/Models/ManageViewModels.cs create WebApplication/Controllers/AccountController.cs create WebApplication/Controllers/HomeController.cs create WebApplication/Controllers/ManageController.cs create WebApplication/Compiler/Preprocess/RazorPreCompilation.cs create WebApplication/Migrations/000000000000000_CreateIdentitySchema.cs create WebApplication/Migrations/ApplicationDbContextModelSnapshot.cs create WebApplication/Properties/AppSettings.cs create WebApplication/Views/Account/ConfirmEmail.cshtml create WebApplication/Views/Account/ExternalLoginConfirmation.cshtml create WebApplication/Views/Account/ExternalLoginFailure.cshtml create WebApplication/Views/Account/ForgotPassword.cshtml create WebApplication/Views/Account/ForgotPasswordConfirmation.cshtml create WebApplication/Views/Account/Login.cshtml create WebApplication/Views/Account/Register.cshtml create WebApplication/Views/Account/ResetPassword.cshtml create WebApplication/Views/Account/ResetPasswordConfirmation.cshtml create WebApplication/Views/Account/SendCode.cshtml create WebApplication/Views/Account/VerifyCode.cshtml create WebApplication/Views/Home/Contact.cshtml create WebApplication/Views/Home/About.cshtml create WebApplication/Views/Home/Index.cshtml create WebApplication/Views/Manage/AddPhoneNumber.cshtml create WebApplication/Views/Manage/ChangePassword.cshtml create WebApplication/Views/Manage/Index.cshtml create WebApplication/Views/Manage/ManageLogins.cshtml create WebApplication/Views/Manage/RemoveLogin.cshtml create WebApplication/Views/Manage/SetPassword.cshtml create WebApplication/Views/Manage/VerifyPhoneNumber.cshtml create WebApplication/Views/Shared/Error.cshtml create WebApplication/Views/Shared/_Layout.cshtml create WebApplication/Views/Shared/_LoginPartial.cshtml create WebApplication/Views/Shared/_ValidationScriptsPartial.cshtml create WebApplication/Views/_GlobalImport.cshtml create WebApplication/Views/_ViewStart.cshtml create WebApplication/wwwroot/_references.js create WebApplication/wwwroot/css/site.css create WebApplication/wwwroot/favicon.ico create WebApplication/wwwroot/images/ASP-NET-Banners-01.png create WebApplication/wwwroot/images/ASP-NET-Banners-02.png create WebApplication/wwwroot/images/Banner-01-Azure.png create WebApplication/wwwroot/images/Banner-02-VS.png create WebApplication/wwwroot/lib/bootstrap-touch-carousel/css/bootstrap-touch-carousel.css create WebApplication/wwwroot/lib/bootstrap-touch-carousel/js/bootstrap-touch-carousel.js create WebApplication/wwwroot/lib/bootstrap/css/bootstrap-theme.css create WebApplication/wwwroot/lib/bootstrap/css/bootstrap-theme.min.css create WebApplication/wwwroot/lib/bootstrap/css/bootstrap.css create WebApplication/wwwroot/lib/bootstrap/css/bootstrap.min.css create WebApplication/wwwroot/lib/bootstrap/fonts/glyphicons-halflings-regular.eot create WebApplication/wwwroot/lib/bootstrap/fonts/glyphicons-halflings-regular.svg create WebApplication/wwwroot/lib/bootstrap/fonts/glyphicons-halflings-regular.ttf create WebApplication/wwwroot/lib/bootstrap/fonts/glyphicons-halflings-regular.woff create WebApplication/wwwroot/lib/bootstrap/js/bootstrap.js create WebApplication/wwwroot/lib/bootstrap/js/bootstrap.min.js create WebApplication/wwwroot/lib/hammer.js/hammer.js create WebApplication/wwwroot/lib/hammer.js/hammer.min.js create WebApplication/wwwroot/lib/hammer.js/hammer.min.map create WebApplication/wwwroot/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js create WebApplication/wwwroot/lib/jquery-validation/jquery.validate.js create WebApplication/wwwroot/lib/jquery/jquery-migrate.js create WebApplication/wwwroot/lib/jquery/jquery-migrate.min.js create WebApplication/wwwroot/lib/jquery/jquery.js create WebApplication/wwwroot/lib/jquery/jquery.min.js create WebApplication/wwwroot/lib/jquery/jquery.min.map Your project is now created, you can use the following commands to get going dnu restore dnu build dnx . run for console projects dnx . kestrel or dnx . web for web projects _-----_ | | .----------------------. |--(o)--| | Bye from us! | `---------´ | Chat soon. | ( _´U`_ ) | Yeoman team | /___A___\ | http://yeoman.io | | ~ | '----------------------' __'.___.'__ ´ ` |° ´ Y `
太麻煩了?看看動畫吧。
資料來源:http://blogs.msdn.com/b/webdev/archive/2014/12/17/yeoman-generators-for-asp-net-vnext.aspx
在輸出的最後,已經說明咱們須要的工做。執行 dnu restore, 可是,報錯了。
Restoring packages for /Users/Openxlive/Desktop/helloWeb/WebApplication/project.json Writing lock file /Users/Openxlive/Desktop/helloWeb/WebApplication/project.lock.json npm WARN package.json WebApplication@0.0.0 No description npm WARN package.json WebApplication@0.0.0 No repository field. npm WARN package.json WebApplication@0.0.0 No README data grunt@0.4.5 node_modules/grunt ├── which@1.0.9 ├── dateformat@1.0.2-1.2.3 ├── eventemitter2@0.4.14 ├── getobject@0.1.0 ├── rimraf@2.2.8 ├── colors@0.6.2 ├── async@0.1.22 ├── hooker@0.2.3 ├── grunt-legacy-util@0.2.0 ├── exit@0.1.2 ├── nopt@1.0.10 (abbrev@1.0.5) ├── lodash@0.9.2 ├── minimatch@0.2.14 (sigmund@1.0.0, lru-cache@2.6.2) ├── glob@3.1.21 (inherits@1.0.0, graceful-fs@1.2.3) ├── coffee-script@1.3.3 ├── underscore.string@2.2.1 ├── iconv-lite@0.2.11 ├── findup-sync@0.1.3 (glob@3.2.11, lodash@2.4.2) ├── grunt-legacy-log@0.1.1 (underscore.string@2.3.3, lodash@2.4.2) └── js-yaml@2.0.5 (esprima@1.0.4, argparse@0.1.16) grunt-bower-task@0.4.0 node_modules/grunt-bower-task ├── colors@0.6.2 ├── async@0.1.22 ├── wrench@1.4.4 ├── rimraf@2.0.3 (graceful-fs@1.1.14) ├── lodash@0.10.0 └── bower@1.3.12 (is-root@1.0.0, junk@1.0.1, stringify-object@1.0.1, which@1.0.9, abbrev@1.0.5, chmodr@0.1.0, osenv@0.1.0, archy@0.0.2, opn@1.0.2, rimraf@2.2.8, bower-logger@0.2.2, bower-endpoint-parser@0.2.2, graceful-fs@3.0.6, lockfile@1.0.0, lru-cache@2.5.2, nopt@3.0.1, retry@0.6.0, tmp@0.0.23, q@1.0.1, request-progress@0.3.0, shell-quote@1.4.3, chalk@0.5.0, semver@2.3.2, bower-json@0.4.0, fstream@1.0.6, p-throttler@0.1.0, mkdirp@0.5.0, promptly@0.2.0, bower-config@0.5.2, fstream-ignore@1.0.2, tar-fs@0.5.2, decompress-zip@0.0.8, request@2.42.0, glob@4.0.6, bower-registry-client@0.2.4, cardinal@0.4.0, mout@0.9.1, inquirer@0.7.1, insight@0.4.3, handlebars@2.0.0, update-notifier@0.2.0) ---------- System.ComponentModel.Win32Exception: ApplicationName='bower', CommandLine='install', CurrentDirectory='/Users/Openxlive/Desktop/helloWeb/WebApplication', Native error= Cannot find the specified file at System.Diagnostics.Process.Start_noshell (System.Diagnostics.ProcessStartInfo startInfo, System.Diagnostics.Process process) [0x00000] in <filename unknown>:0 at System.Diagnostics.Process.Start_common (System.Diagnostics.ProcessStartInfo startInfo, System.Diagnostics.Process process) [0x00000] in <filename unknown>:0 at System.Diagnostics.Process.Start (System.Diagnostics.ProcessStartInfo startInfo) [0x00000] in <filename unknown>:0 at Microsoft.Framework.PackageManager.ScriptExecutor.Execute (Microsoft.Framework.Runtime.Project project, System.String scriptName, System.Func`2 getVariable) [0x00000] in <filename unknown>:0 at Microsoft.Framework.PackageManager.RestoreCommand+<RestoreForProject>d__69.MoveNext () [0x00000] in <filename unknown>:0 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00000] in <filename unknown>:0 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00000] in <filename unknown>:0 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00000] in <filename unknown>:0 at System.Runtime.CompilerServices.TaskAwaiter`1[System.Boolean].GetResult () [0x00000] in <filename unknown>:0 at Microsoft.Framework.PackageManager.RestoreCommand+<>c__DisplayClass68_0+<<ExecuteCommand>b__0>d.MoveNext () [0x00000] in <filename unknown>:0 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00000] in <filename unknown>:0 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00000] in <filename unknown>:0 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00000] in <filename unknown>:0 at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <filename unknown>:0 at Microsoft.Framework.PackageManager.RestoreCommand+<ExecuteCommand>d__68.MoveNext () [0x00000] in <filename unknown>:0 ---------- Restore failed ApplicationName='bower', CommandLine='install', CurrentDirectory='/Users/Openxlive/Desktop/helloWeb/WebApplication', Native error= Cannot find the specified file
看樣子是少了一個 bower 組件,從新安裝一下吧。
sudo npm install -g bower
輸出以下:
/usr/local/bin/bower -> /usr/local/lib/node_modules/bower/bin/bower bower@1.4.1 /usr/local/lib/node_modules/bower ├── is-root@1.0.0 ├── junk@1.0.1 ├── stringify-object@1.0.1 ├── user-home@1.1.1 ├── abbrev@1.0.5 ├── chmodr@0.1.0 ├── rimraf@2.3.3 ├── archy@1.0.0 ├── opn@1.0.2 ├── bower-logger@0.2.2 ├── bower-endpoint-parser@0.2.2 ├── graceful-fs@3.0.6 ├── lockfile@1.0.0 ├── nopt@3.0.1 ├── lru-cache@2.6.2 ├── retry@0.6.1 ├── tmp@0.0.24 ├── q@1.4.0 ├── semver@2.3.2 ├── p-throttler@0.1.1 (q@0.9.7) ├── fstream@1.0.6 (inherits@2.0.1) ├── promptly@0.2.0 (read@1.0.5) ├── which@1.1.1 (is-absolute@0.1.7) ├── tar-fs@1.5.0 (pump@1.0.0, tar-stream@1.1.4) ├── request-progress@0.3.1 (throttleit@0.0.2) ├── glob@4.5.3 (inherits@2.0.1, once@1.3.2, inflight@1.0.4, minimatch@2.0.7) ├── fstream-ignore@1.0.2 (inherits@2.0.1, minimatch@2.0.7) ├── chalk@1.0.0 (ansi-styles@2.0.1, escape-string-regexp@1.0.3, supports-color@1.3.1, strip-ansi@2.0.1, has-ansi@1.0.3) ├── github@0.2.4 (mime@1.3.4) ├── mkdirp@0.5.0 (minimist@0.0.8) ├── cardinal@0.4.4 (ansicolors@0.2.1, redeyed@0.4.4) ├── mout@0.11.0 ├── bower-config@0.6.1 (osenv@0.0.3, graceful-fs@2.0.3, optimist@0.6.1, mout@0.9.1) ├── handlebars@2.0.0 (optimist@0.3.7, uglify-js@2.3.6) ├── decompress-zip@0.1.0 (mkpath@0.1.0, touch@0.0.3, readable-stream@1.1.13, binary@0.3.0) ├── shell-quote@1.4.3 (array-filter@0.0.1, array-reduce@0.0.0, array-map@0.0.0, jsonify@0.0.0) ├── bower-json@0.4.0 (graceful-fs@2.0.3, intersect@0.0.3, deep-extend@0.2.11) ├── inquirer@0.8.0 (figures@1.3.5, ansi-regex@1.1.1, mute-stream@0.0.4, through@2.3.7, readline2@0.1.1, chalk@0.5.1, lodash@2.4.2, rx@2.5.2, cli-color@0.3.3) ├── request@2.53.0 (caseless@0.9.0, json-stringify-safe@5.0.0, forever-agent@0.5.2, aws-sign2@0.5.0, stringstream@0.0.4, tunnel-agent@0.4.0, oauth-sign@0.6.0, isstream@0.1.2, node-uuid@1.4.3, qs@2.3.3, form-data@0.2.0, combined-stream@0.0.7, tough-cookie@1.1.0, bl@0.9.4, hawk@2.3.1, mime-types@2.0.11, http-signature@0.10.1) ├── bower-registry-client@0.3.0 (graceful-fs@2.0.3, request-replay@0.2.0, rimraf@2.2.8, lru-cache@2.3.1, async@0.2.10, mkdirp@0.3.5, request@2.51.0) ├── insight@0.5.3 (object-assign@2.0.0, async@0.9.0, lodash.debounce@3.0.3, tough-cookie@0.12.1, os-name@1.0.3) ├── update-notifier@0.3.2 (is-npm@1.0.0, string-length@1.0.0, semver-diff@2.0.0, latest-version@1.0.0) └── configstore@0.3.2 (object-assign@2.0.0, xdg-basedir@1.0.1, osenv@0.1.0, uuid@2.0.1, js-yaml@3.3.0)
把 grunt 也安裝一下。
sudo npm install -g grunt-cli
輸出。
/usr/local/bin/grunt -> /usr/local/lib/node_modules/grunt-cli/bin/grunt grunt-cli@0.1.13 /usr/local/lib/node_modules/grunt-cli ├── resolve@0.3.1 ├── nopt@1.0.10 (abbrev@1.0.5) └── findup-sync@0.1.3 (lodash@2.4.2, glob@3.2.11)
從新 restore ,終於成功了。
Restoring packages for /Users/Openxlive/Desktop/helloWeb/WebApplication/project.json Writing lock file /Users/Openxlive/Desktop/helloWeb/WebApplication/project.lock.json npm WARN package.json WebApplication@0.0.0 No description npm WARN package.json WebApplication@0.0.0 No repository field. npm WARN package.json WebApplication@0.0.0 No README data Running "bower:install" (bower) task >> Installed bower packages >> Copied packages to /Users/Openxlive/Desktop/helloWeb/WebApplication/wwwroot/lib Done, without errors. Restore complete, 12380ms elapsed
運行網站。
dnx . kestrel
Started
打開瀏覽器,訪問地址: http://localhost:5001
竟然又報了一個錯誤。
An unhandled exception occurred while processing the request. IOException: kqueue() FileSystemWatcher has reached the maximum nunmber of files to watch. System.IO.KqueueMonitor.Add (System.String path, Boolean postEvents, System.Collections.Generic.List`1& fds) [0x00000] in <filename unknown>, line 0
這是 Mono 的一個已知錯誤,須要一個設置。
export MONO_MANAGED_WATCHER=false
再次運行,終於能夠看到網站了。