[ASP.NET 5]KVM(K version manager)

  • 865
  • 0

本文承前一篇「從空的Web專案到使用MVC」的範例,來介紹 KVM ,並讓Web AP 可以從 Command 視窗啟動。

環境:Visual Studio 2015 CTP6

本文承前一篇「從空的Web專案到使用MVC」的範例,來介紹 KVM ,並讓Web AP 可以從 Command 視窗啟動。

 

在安裝過了 Visual Studio 2015 的機器中,C:\Users\[使用者]\.k\runtimes裡面有各版本的 CLR runtime,如下,

image

 

在版本裡面的bin目錄除了有DLL外,也有cmd 及 exe files

例如 k.cmd, kmp.cmd 在command line執行,或是bundle起來deploy應用程式,而在執行它們之前,要選對所在的Path。

image

 

ASP.NET 提供 tool 讓我們很容易的切換 不同 version 的 runtime

那個Tool就是 KVM ,預設並不會安裝它。

如果要安裝 KVM(Install the .NET Version Manager (DNVM)),可連到 https://github.com/aspnet/home

然後用 kvm來找,然後 copy powershell 到command 執行,它會後 github 上面 download powershell script來執行,並設定環境變數及Path。

image

 

@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/master/kvminstall.ps1'))"

image

 

安裝完成後,可以輸入 kvm,kvm可以讓我們 升級、安裝或使用不同版本

image

 

可以輸入 kvm list 可以看看目前有那些版本,如下,

image

 

這時我們切到WebAP的根目錄(有project.json那個目錄),這時輸入 k 會發生錯誤,因為我們還沒有設定使用那個版本,如下,

image

 

輸入 kvm use 1.0.0-beta3 -r CoreCLR 來切換要使用的 runtime,如下,

image

 

再來我們要在 project.json 中加入 commands ,讓我們的 Web AP 可以 Host 在 Microsoft.AspNet.Hosting  上,可以從Command 視窗啟動,所以新增 commands,如下,

"commands":{

"web":"Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener -- server.urls http://localhost:3800 "

}

 

因為會用到 WebListener ,所以 dependencies 也要加入

"dependencies":{

"Microsoft.AspNet.Server.WebListener": ""

}

 

再來到 Command 視窗輸入 k web ,它會回應 Started ,表示已正常啟動了。

image

 

再開啟 Browser 來瀏灠  http://localhost:3800 ,就可以看到正確的結果哦!

image

 

參考資料

ASP.NET 5: First Look

從空的Web專案到使用MVC

安裝 KVM (K Version Manager) 及 KRE (K Runtime Environment)

Hi, 

亂馬客Blog已移到了 「亂馬客​ : Re:從零開始的軟體開發生活

請大家繼續支持 ^_^