
Announcing .NET Core and ASP.NET 5 RC1
Today, we are announcing .NET Core and ASP.NET 5 Release Candidate, supported on Windows, OS X and Linux. This release is "Go Live", meaning you can deploy apps into production and call Microsoft Support if you need help. Please check out theAnnouncing ASP.NET 5 RC blog post to learn more about the updates to ASP.NET 5.
這篇我分幾個角度來探討 .NET Core. 如果你是想看 Step by step 的教學,或是想看看新版本有甚麼功能,或是哪裡下載等等,那請直接 Google 新聞或是官網就可以了。我的重點會擺在我的研究過程發現的心得,一些官方文件上沒寫的資訊,以及我研究過程得到的結論跟想法等等。接下來這系列我會談到這幾個主題,一篇寫不完的話就請各位等待續集了~ Progrmming / Coding 相關的探討,我本來就會定期分享,因此這系列文章我會著重在跨平台以及 .NET Core 本身的改進,還有原本就用 Microsoft Solution 的企業,導入 .NET Core + Linux 後帶來的效益。主題包括:- DOTNET CLI, 跟 BETA 時期的 DNX / DNVM / DNU 的關係
- DOTNET CLI 搭配 Docker 的使用技巧
- CODING 實際上機: Hello World (Console)
- (下回分曉) Inside .NET Core Runtime, Windows / Linux 的差異 #1, Compute PI (performance)
- (下回分曉) Inside .NET Core Runtime, Windows / Linux 的差異 #2, Memory Fragment Test (memory management)
- (下回分曉) (還在想...)
新玩意: DOTNET CLI, 整合 DNVM / DNX / DNU 的命令列工具
隨著這次的 RC1 Announcing, 原本 Beta 時代的那些命令列工具, 也開始有新版本了。原本的工具分別負責 RUNTIME 的管理 (DNVM),執行 (DNX),維護 (DNU).. 現在被集中在同一個指令 dotnet 底下了,也就是這次新發布的 DOTNET CLI。 不過這個 CLI (Command Line Interface) 版本還很前期,看她的編號才 0.01 alpha , 離正式版本還很久,因此這次是分成兩個 container image 發行:- microsoft/aspnet: 這個 image 還是跟上次介紹文章寫的一樣,用的是 DNVM / DNX / DNU 這組指令,指示相關的版本已經升級到 RC1,使用方式跟前幾篇文章介紹的都一樣,這次就略過,後面應用測試時有需要再拿他出來..
- microsoft/dotnet: 這個則是另一個新的 image, 裡面放的就是 .NET Core 新版的命令列工具 (v0.0.1-alpha preview). 功能差不多,不過比之前有組織的多。DNVM / DNX / DNU 這些指令第一次看到還真的會搞混,從名字完全看不出是幹嘛用的,新版工具的命名就清楚的多,同時也追加了一些新功能,像是編譯成 Nativa Code 等等,這些是之前 Beta 版時期還沒有的機制
DOTNET CLI Container 的使用技巧
開始介紹我的使用方式錢,先把幾個關鍵的參考資訊貼一下... 現在的參考資料還不是很多,除了官方少少的幾份資料之外,碰到問題根本還 Google 不到甚麼東西,只能自己憑經驗摸索 @@- 來自 Microsoft GitHub 的 Readme: .NET CLI Preview Docker Image
- 來自 Microsoft GitHub 的 Quick-Start 說明: It is very easy to get started with .NET Core on your platform of choice.
- ASP.NET 5 and .NET Core RC1 in context (Plus all the Connect 2015 News)
- .NET Blog / Announcing .NET Core and ASP.NET 5 RC
- .NET Web Dev and Tools Blog / Announcing ASP.NET 5 Release Candidate 1
- ScottGu's Blog / Introducing ASP.NET 5
- Scott Hanselman / Visual Studio 2015 Released plus ASP.NET 5 Roadmap
Compile your app inside the Docker container
There may be occasions where it is not appropriate to run your app inside a container. To compile, but not run your app inside the Docker instance, you can write something like:
$ docker run --rm -v "$PWD":/myapp -w /myapp microsoft/dotnet:0.0.1-alpha dotnet compile
This will add your current directory as a volume to the container, set the working directory to the volume, and run the command dotnet compile
which will tell dotnet to compile the project in the working directory.
chicken@localhost:~$ sudo docker pull microsoft/dotnet
chicken@localhost:~$ sudo docker run --name dotnet --rm -t -i microsoft/dotnet /bin/bash root@6b021f6be610:/#第一行的 prompt 提示訊息還是 Linux Host OS, 執行成功之後,第二行的 prompt 就換成 Container 內的 shell ,代表執行成功! 如果你有現成的 code 想丟進去 Container 編輯使用,可以用 -v 加掛 volume 進去,不過我這邊的範例還不需要,我就略過了。接下來就進入這套新的 CLI: dotnet. 先來看看 dotnet cli 到底支援幾種命令?
root@6b021f6be610:/# dotnet -h
root@6b021f6be610:/tmp/HelloWorld# dotnet init
root@6b021f6be610:/tmp/HelloWorld# dotnet restore
root@6b021f6be610:/tmp/HelloWorld# dotnet compile -h
root@6b021f6be610:/tmp/HelloWorld# dotnet compile
root@6b021f6be610:/tmp/HelloWorld# dotnet run