Mac OS 環境下 安裝 Asp.Net及使用Yeoman 建立Asp.Net 項目,yeomanasp.net

來源:互聯網
上載者:User

Mac OS 環境下 安裝 Asp.Net及使用Yeoman 建立Asp.Net 項目,yeomanasp.net

本文是按照英文原文:Installing ASP.NET 5 On Mac OS安裝時遇到的問題的總結Blog。

原文提示如下:

Installing ASP.NET 5 On Mac OS X
By Steve Smith

ASP.NET 5 runs on the .NET Execution Environment (DNX), which is available on multiple platforms, including OS X. This article describes how to install DNX, and therefore ASP.NET 5, on OS X, using Homebrew.

In this article:
Install ASP.NET 5 on OS X
Install ASP.NET 5 on OS X
ASP.NET 5 requires DNX, which is installed and managed by the .NET Version Manager (DNVM). The DNVM is easily installed using a tool called Homebrew, which will also install the correct version of Mono for OS X.

Install Homebrew
The first step is to install Homebrew if it's not already installed. This can be done from a Terminal prompt using this script:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"



The installer will inform you of the steps it is taking and pause before proceeding. You can learn more about Homebrew here.

到這一步,可能會出現 brew 已經安裝了。


可以執行:

brew -v




Install the .NET Version Manager (DNVM)
Once Homebrew is installed, install the DNVM by running brew tap aspnet/dnx from a Terminal window. If you need to update your version of DNVM, first run brew untap aspnet/dnx to delete the old commands, and then run the brew tap aspnet/dnx command again to get the updated scripts.


If you had an older version of our Homebrew "tap" configured, you might get the following error: Could not create link for aspnet/dnx/kvm, as it conflicts with aspnet/k/kvm. In that case, simply run brew uninstall kvm to ensure any old versions of kvm are removed, then brew untap aspnet/k to remove the old tap. After that, the brew tap aspnet/dnx command should succeed.

Next, run the command brew install dnvm to install the .NET Version Manager. This will also automatically install the latest DNX package from the https://www.nuget.org/api/v2 feed.

這一步可能出現沒有許可權的問題:


執行

chown root:wheel /usr/local/bin/brew


然後執行

brew link mono



完成安裝。 一切正常了。

Next, run dnvm to verify that your terminal understands this command. If it does not, run the command source dnvm.sh to link it, then try running dnvm again. You should see something like this:

 

使用Yemoman 建立Asp.net 項目

Mac 上 Asp.net 環境搭建好了以後,自己手動去開始一個 Asp.net 項目,是比較繁瑣的。 Yeoman 上已經有 Asp.net 的 generator.

如果沒有 Yeoman 先安裝 Yeoman, Yeoman 的介紹: http://yeoman.io/ Yeoman下面有各種項目基礎架構的generator

> npm install -g yo



安裝 Asp.net generator

> npm install -g generator-aspnet



使用 yeoman 開啟一個 Asp.Net 項目

> yo aspnet


這裡使用 Nacy 架構, Nacy的介紹: http://nancyfx.org/ 一個輕量級的 .Net Web Framework

選擇 Nacy ASP.Net Application


同時給一個項目名字,這裡用了 NacyApp


項目基礎檔案架構就生產了。

進入 NacyApp 目錄

執行

dnu restore 



載入 依賴


如果 dnu 命令執行失敗, commond not found.

執行命令:

source dnvm.sh



如果執行 dnu restore 出現 http://nuget.org/api/v2/ 取依賴包找不到的問題,切換一下源再試試,有兩個可用的源:

1. https://www.myget.org/F/aspnetmaster/api/v2/
2. https://www.myget.org/F/aspnetvnext/api/v2/ 

例如:

dnu restore -s "https://www.myget.org/F/aspnetmaster/api/v2"



可以使用 core visual studio 開啟工程,開始寫程式。


然後 dnx . kestrel 開始你的 NacyApp 就可以了




這裡有個有意思的事情,在terminal 裡執行了 dnx . kestrel 後,如果想退出, 執行 ctrl+c 了以後,看到 terminal 沒有反應,在瀏覽器裡重新整理一下頁面, terminal 會出一個錯誤, 就退出了。

 

原部落格地址:http://zhangsichu.com/blogview.asp?Content_Id=151                  http://zhangsichu.com/blogview.asp?Content_Id=153

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.