【dotnet跨平台】最新版dotnet-cli下的ASP.NET Core和asp.net mvc【RC2尝鲜】
2016-04-03 15:12
941 查看
【dotnet跨平台】最新版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效果如下:
相关文章推荐
- ASP.NET MVC案例教程(基于ASP.NET MVC beta)——第二篇:第一个页面
- ASP.NET MVC案例教程(基于ASP.NET MVC beta)——第一篇:准备工作
- 动画队列,第一个动画的字体变大和第二个动画的元素高度增加同时进行,两个动画完成之后,才触发第3个动画
- ASP.NET生成验证码
- 【java】解决JDK出现Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=gasp的问题
- 个人网站实现扫码登录asp.net 扫码登录
- asp.net MVC控制器返回json问题总结
- asp 后台获取 input 的值
- ASP.NET MVC HtmlHelper之Html.ActionLink
- ssh整合context:component-scan包名写了*号:Failed to parse configuration class [org.springframework.cache.aspectj.AspectJJCacheConfiguration]
- [Asp.net 开发系列之SignalR篇]专题一:Asp.net SignalR快速入门
- raspberry pi 2 install Ubuntu 14.04 LTS
- Win10 兼容性 Visual studio web应用程序 ASP.NET 4.0 尚未在 Web 服务器上注册
- ASP.NET MVC EF 01 框架搭建
- 2016-AspNet-MVC教学-8-异步Controller的应用
- asp.net mvc源码分析-ModelValidatorProviders 客户端的验证
- ASP.NET总结
- asp.net Routing 用法
- asp.net mvc源码分析-ModelValidatorProviders 客户端的验证
- HTML与Aspx的区别