First ASP.NET Core Application on a Mac Using Visual Studio Code

一直但願能夠在mac上直接編寫webapp (用C#)如今終於伴隨着 core 世界美好了,不須要用pd windows了 nice。 html

Visual studio code 更新1.1版本了

懷着激動的心情嘗試一下在mac上運行asp.net5 core application node

首先你要下載 visual studio code git

https://www.visualstudio.com/zh-cn/products/code-vs.aspx github

安裝ASP.NET 5 DNX(.NET執行環境)

dnx asp.net5 core的核心 web

github:https://github.com/aspnet/home#os-x macos

官網:https://www.microsoft.com/net npm

osx:https://www.microsoft.com/net/core#macosx json

  1. Install pre-requisites

爲了使用.NET的核心,你須要安裝OpenSSL版本的更新 bootstrap

http://brew.sh/index_zh-cn.html windows

安裝完成之後進入下一步:

        brew update

        brew install openssl

        brew link --force openssl

  1. Install .NET Core SDK

在你開始以前刪除全部之前的版本,從你的系統中的網絡核心,使用這個腳本。

https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0/scripts/obtain/uninstall/dotnet-uninstall-pkgs.sh

官方安裝包安裝的最好方式。在OS X核心是利用官方PKG包。這個安裝程序將安裝這些工具並將它們放在你的路徑上。

https://go.microsoft.com/fwlink/?LinkID=798400

  1. Initialize some code

如今能夠寫一個hello word 了。

mkdir hwapp :建立文件夾

cd hwapp :跳轉路徑

dotnet new :建立一個C#項目到hwapp文件夾

  1. Run the app

dotnet restore:恢復在project.json文件指定的包

dotnet run:執行應用

  1. and you're set!

你如今能夠去github上看源代碼了(無論你看不看 我反正沒看)

What's Yeoman?

若是你來從Visual Studio .NET IDE 走過來的人,你會想,"是否有文件>新建> ASP.NET項目模板?"。 Visual Studio Code是基於文件的代碼編輯器,它使你能夠只打開一個文件,並開始編輯。 所以,咱們將須要一些外部的幫助,讓咱們的ASP.NET項目模板加載。

Yeoman是一個流行的命令行工具,還提供了一個基本的ASP.NET模板開始。 Yeoman可以使用NPM安裝,這意味着你將須要安裝Node.js(https://nodejs.org/en/download/)。

除了Yeoman,咱們還須要一些其餘的輔助工具,如ASP.NET GeneratorGrunt task runner and Bower。 您能夠在一個命令執行此操做。 在命令提示符處鍵入如下命令,而後按Enter鍵:

npm install –g yo grunt-cli generator-aspnet bower(報錯)

看到這個就正常了!不要用node.js 4.4.4用最新的6.2.0

總結以下:

建立Web應用程序

讓咱們經過scaffold建立一個新的ASP.NET 5 Web應用程序。

  1. 打開命令提示符,並要在其中建立新的Web應用程序導航到該位置

    cd hwapp

2.在命令提示符下輸入如下命令 


yo aspnet

控制檯應用程序

Web應用程序

網絡應用基礎(沒有會員/驗證)

網頁API應用程序

nancy ASP.NET應用程序

類庫

單元測試項目

咱們選擇(網絡應用基礎(沒有會員/驗證))

繼續選擇bootstrap 3.3.6

輸入項目名稱(hwapp)

完成後會有以下提示:

 

Your project is now created, you can use the following commands to get going

cd "hwapp"

dotnet restore

dotnet build (optional, build will also happen when it's run)

dotnet run

若是建立項目報上圖錯誤

一般yeoman錯誤從新安裝what's yeoman 步驟。

正常後以下圖:

相關文章
相關標籤/搜索