最新版dotnet-cli下的ASP.NET Core和asp.net mvc【RC2尝鲜】
RC1是http://get.asp.net里面提供的https://docs.asp.net/en/latest/getting-started/index.html,使用舊的ASP.NET Core 1.0。這個版本會使用dnvm,dnu restore和dnx web等,而RC2則不需要,RC2只需要dotnet restore和dotnet run,無論是對控制臺程序還是web程序。
RC2就是在RC1的基礎上從ASP.NET Core 1.0遷移到基于dotnet-cli或者.NET Core CLI的跨平臺產品。
聲明下,RC2還沒出來,這里使用的是正在開發的RC2版本的最新版本。
想試下最新版dotnet-cli下的ASP.NET Core和asp.net mvc,可以參考http://dotnet.github.io/getting-started/和https://github.com/aspnet/cli-samples。
【注:】舊方法是使用dnx和mono:https://docs.asp.net/en/latest/getting-started/installing-on-linux.html
【方法一,這個方法嘗試失敗了,請不要再次嘗試】
具體在Linux端運行如下命令(本人使用的是Ubuntu Server 14.04 x64,下載地址:http://www.ubuntu.com/download/server):
sh -c 'echo "deb [arch=amd64] http://apt-mo.trafficmanager.net/repos/dotnet/ trusty main" > /etc/apt/sources.list.d/dotnetdev.list'
apt-key adv --keyserver apt-mo.trafficmanager.net --recv-keys 417A0893
apt-get update
apt-get install dotnet=1.0.0.001675-1
想看最新版dotnet是多少看這個:http://apt-mo.trafficmanager.net/repos/dotnet/pool/main/d/dotnet/, 我這里安裝的是最新版1.0.0.001675-1版本。
cd /var
mkdir aspnet
cd /var/aspnet
cd aspnet
git clone https://github.com/aspnet/cli-samples.git
cd cli-samples
dotnet restore
安裝完之后,發現有個bug"unknown keyword platform":https://github.com/aspnet/cli-samples/issues/32,官網的步驟不再適用當前cli-samples,解決方法是到這里下載最新版:https://github.com/dotnet/cli#installers-and-binaries
【方法二,這個方法成功,大家可以試試】
https://github.com/dotnet/cli#installers-and-binaries或者https://github.com/dotnet/cli顯示了最新版本是1.0.0-beta-002202版本
3個deb都下載下來:
cd /var/aspnet
wget http://dotnetcli.blob.core.windows.net/dotnet/beta/Installers/Latest/dotnet-host-ubuntu-x64.latest.deb
wget http://dotnetcli.blob.core.windows.net/dotnet/beta/Installers/Latest/dotnet-sharedframework-ubuntu-x64.latest.deb
wget http://dotnetcli.blob.core.windows.net/dotnet/beta/Installers/Latest/dotnet-sdk-ubuntu-x64.latest.deb
先刪除之前安裝的舊版的:apt-get remove dotnet=1.0.0.001675-1
dpkg -i dotnet-host-ubuntu-x64.latest.deb
dpkg -i dotnet-sharedframework-ubuntu-x64.latest.deb
dpkg -i dotnet-sdk-ubuntu-x64.latest.deb
安裝完成之后,開始嘗試下能不能用了:
cd /var/aspnet/cli-samples
cd HelloMvc
dotnet restore
dotnet run
http://localhost:5000
如何改變監聽IP地址和端口?在這里找到了答案:https://github.com/aspnet/KestrelHttpServer/issues/639
把Program.cs加一行代碼如下:
using System.IO;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Builder;
namespace HelloMvc
{
? ? public class Program
? ? {
? ? ? ? public static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? var host = new WebHostBuilder()
? ? ? ? ? ? ? ? ? ? ? ? .UseKestrel()
? ? ? ? ? ? ? ? ? ? ? ? .UseContentRoot(Directory.GetCurrentDirectory())
? ? ? ? ? ? ? ? ? ? ? ? .UseDefaultHostingConfiguration(args)
? ? ? ? ? ? ? ? ? ? ? ? .UseIIS()
? ? ? ? ? ? ? ? ? ? ? ? .UseStartup<Startup>()
? ? ? ? ? ? ? ? ? ? ? ? .UseUrls("http://*:8888")
? ? ? ? ? ? ? ? ? ? ? ? .Build();
? ? ? ? ? ? host.Run();
? ? ? ? }
? ? }
}
運行dotnet run效果如下:
原文地址:http://blog.csdn.net/yangzhenping/article/details/51050459
.NET社區新聞,深度好文,微信中搜索dotNET跨平臺或掃描二維碼關注
贊賞
人贊賞
總結
以上是生活随笔為你收集整理的最新版dotnet-cli下的ASP.NET Core和asp.net mvc【RC2尝鲜】的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: AutoMapper 使用实践
- 下一篇: .NET的未来包含一个开源的Mono