ASP.NET Core RC2 终于发布了( Announcing ASP.NET Core RC2 )。为了庆祝这次发布,我们将运行在 Ubuntu 服务器上的示例站点 about.cnblogs.com 升级到了 ASP.NET Core RC2 ,在这篇博文中分享一下我们在升级过程中遇到的问题。

一、安装.NET Core SDK

删除旧版 dotnet cli:

rm -rf /usr/share/dotnet

安装 .NET Core SDK:

curl -sSL https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0/scripts/obtain/dotnet-install.sh | bash /dev/stdin --version 1.0.0-preview1-002702 --install-dir ~/dotnet
sudo ln -s ~/dotnet/dotnet /usr/local/bin

二、运行 dotnet restore 命令

遇到2个错误:

1) Unable to resolve 'Microsoft.AspNetCore.IISPlatformHandler (>= 1.0.0)' for '.NETCoreApp,Version=v1.0'

解决方法:在 project.json 中将 Microsoft.AspNetCore.IISPlatformHandler 改为 Microsoft.AspNetCore.Server.IISIntegration 。

2) Package Newtonsoft.Json 7.0.1 is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0)

解决方法:在 project.json 中将

"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-*"
}

改为

"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools":{
"version":"1.0.0-*",
"imports": "portable-net45+win8+dnxcore50"
}
}

详见博问:http://q.cnblogs.com/q/82384/

三、运行 dotnet run 命令

遇到了不少错误:

1)

The type or namespace name 'IApplicationEnvironment' could not be found (are you missing a using directive or an assembly reference?)

解决方法:将 Startup.cs 中的 IApplicationEnvironment 改为 IHostingEnvironment,详见 http://q.cnblogs.com/q/82388/

2)

'IWebHostBuilder' does not contain a definition for 'UseDefaultHostingConfiguration' and no extension method 'UseDefaultHostingConfiguration' accepting a first argument of type 'IWebHostBuilder' could be found (are you missing a using directive or an assembly reference?)

解决方法:在 Program.cs 中删除 .UseDefaultHostingConfiguration(args)

3)

'IWebHostBuilder' does not contain a definition for 'UseIISPlatformHandlerUrl' and no extension method 'UseIISPlatformHandlerUrl' accepting a first argument of type 'IWebHostBuilder' could be found

解决方法:在 Program.cs 中将 .UseIISPlatformHandlerUrl() 改为 UseIISIntegration()

4)

'ConfigurationBuilder' does not contain a definition for 'SetBasePath' and no extension method 'SetBasePath' accepting a first argument of type 'ConfigurationBuilder' could be found

解决方法:在 project.json 的 dependencies 中添加配置: "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0-*" ,详见 http://q.cnblogs.com/q/82391/

5)

'IConfigurationBuilder' does not contain a definition for 'AddJsonFile' and no extension method 'AddJsonFile' accepting a first argument of type 'IConfigurationBuilder' could be found

解决方法:在 project.json 的 dependencies 中添加配置: "Microsoft.Extensions.Configuration.Json": "1.0.0-*" ,详见 http://q.cnblogs.com/q/82395/

6)

The type or namespace name 'IRuntimeEnvironment' does not exist in the namespace 'Microsoft.Extensions.PlatformAbstractions' 

解决方法:在 _Layout.cshtml 中删除 @inject Microsoft.Extensions.PlatformAbstractions.IRuntimeEnvironment env ,添加命名空间 @using Microsoft.Extensions.PlatformAbstractions 与代码 @{ var env = PlatformServices.Default.Runtime; } 。

四、代码改进

在 Program.cs 中将 .UseServer("Microsoft.AspNetCore.Server.Kestrel") 改为 .UseKestrel() 。

五、project.json、Program.cs、Startup.cs中的完整代码

1)project.json

{
"compilationOptions": {
"preserveCompilationContext": true,
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.Extensions.Logging.Console": "1.0.0-*",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-*",
"Microsoft.AspNetCore.HttpOverrides": "1.0.0-*",
"Microsoft.AspNetCore.Mvc": "1.0.0-*",
"Microsoft.AspNetCore.StaticFiles": "1.0.0-*",
"Microsoft.AspNetCore.Diagnostics": "1.0.0-*",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-*",
"Microsoft.Extensions.Configuration.FileExtensions": "1.0.0-*",
"Microsoft.Extensions.Configuration.Json": "1.0.0-*",
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0-*"
}
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"portable-net45+wp80+win8+wpa81+dnxcore50",
"portable-net45+win8+wp8+wpa81",
"portable-net45+win8+wp8"
]
}
}, "tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools":{
"version": "1.0.0-*",
"imports": "portable-net45+win8+dnxcore50"
}
}
}

2)Program.cs

using System.IO;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Builder; namespace CNBlogs.AboutUs.Web
{
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseUrls("http://*:8001")
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build(); host.Run();
}
}
}

3)Startup.cs

using System;
using System.IO;
using System.Linq;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.EntityFrameworkCore;
using CNBlogs.AboutUs.Data;
using Microsoft.Extensions.PlatformAbstractions;
using Microsoft.Extensions.Configuration;
using System.Data.SqlClient;
using Microsoft.Extensions.Logging;
using CNBlogs.AboutUs.Application;
using Microsoft.AspNetCore.Hosting; namespace CNBlogs.AboutUs.Web
{
public class Startup
{
public Startup(IHostingEnvironment hostingEnv)
{
IConfigurationBuilder builder = new ConfigurationBuilder()
.SetBasePath(hostingEnv.ContentRootPath)
.AddJsonFile("config.json", false);
Configuration = builder.Build();
} public IConfiguration Configuration { get; set; } public void Configure(IApplicationBuilder app,
ILoggerFactory loggerFactory,
IHostingEnvironment env)
{
if(env.IsDevelopment())
{
loggerFactory.AddConsole(LogLevel.Debug);
}
else
{
loggerFactory.AddConsole(LogLevel.Error);
} app.UseDeveloperExceptionPage();
app.UseMvcWithDefaultRoute();
app.UseStaticFiles();
app.UseRuntimeInfoPage(); if(env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
} public void ConfigureServices(IServiceCollection services)
{
services.AddMvc(); services.AddEntityFrameworkSqlServer()
.AddDbContext<EfDbContext>(options =>
{
options.UseSqlServer(Configuration["data:ConnectionString"]);
}); services.AddTransient<ITabNavRepository, TabNavRepository>();
services.AddTransient<ITabNavService, TabNavService>();
}
}
}

.NET跨平台之旅:成功将示例站点升级至ASP.NET Core RC2的更多相关文章

  1. .NET跨平台之旅:将示例站点升级至ASP.NET Core 1.0

    北京时间6月28日凌晨,微软发布了 .NET Core 1.0,详见新闻 .NET Core 1.0 正式发布了 ,ASP.NET Core 1.0 也随之一起发布了. 紧跟这次发布,我们将跑在 Li ...

  2. .NET跨平台之旅:将示例站点升级至 ASP.NET Core 1.1

    微软今天在 Connect(); // 2016 上发布了 .NET Core 1.1 ,ASP.NET Core 1.1 以及 Entity Framework Core 1.1.紧跟这次发布,我们 ...

  3. .NET跨平台之旅:将示例站点从 ASP.NET 5 RC1 升级至 ASP.NET Core 1.0

    终于将“.NET跨平台之旅”的示例站点 about.cnblogs.com 从 ASP.NET 5 RC1 升级至 ASP.NET Core 1.0 ,经历了不少周折,在这篇博文中记录一下. 从 AS ...

  4. .NET跨平台之旅:将示例站点从ASP.NET 5 Beta5升级至Beta7

    9月2日,微软发布了ASP.NET 5 Beta7(详见Announcing Availability of ASP.NET 5 Beta7).其中最大的亮点是dnx已经可以完全基于CoreCLR运行 ...

  5. .NET跨平台之旅:将示例站点升级至 .NET Core 1.1 Preview 1

    今天微软发布了 .NET Core 1.1 Preview 1(详见 Announcing .NET Core 1.1 Preview 1 ),紧跟 .NET Core 前进的步伐,我们将示例站点 h ...

  6. .NET跨平台之旅:将示例站点从ASP.NET 5 Beta7升级至RC1

    今天,我们将示例站点(about.cnblogs.com,服务器操作系统是Ubuntu)从ASP.NET 5 Beta7升级到了RC1,在升级过程中只遇到了一个问题. 在运行 dnvm upgrade ...

  7. .NET跨平台之旅:探秘 dotnet run 如何运行 .NET Core 应用程序

    自从用 dotnet run 成功运行第一个 "Hello world" .NET Core 应用程序后,一直有个好奇心:dotnet run 究竟是如何运行一个 .NET Cor ...

  8. .NET跨平台之旅:博问站点迁移至ASP.NET Core on Linux并发布上线

    Powered by ASP.NET Core on Linux! 我们全站的 .NET Core 迁移工作如火如荼,这是我们今年上半年的重要工作. 今天我们终于完成了博问产品(q.cnblogs.c ...

  9. .NET跨平台之旅:在Linux上以本地机器码(native)运行ASP.NET Core站点

    在将“.NET跨平台之旅”示例站点 about.cnblogs.com 从 ASP.NET 5 RC1 升级至 ASP.NET Core 1.0 (博文链接)之后,我们有一个难以抗拒的冲动 —— 体验 ...

随机推荐

  1. 十五天精通WCF——第一天 三种Binding让你KO80%的业务

    转眼wcf技术已经出现很多年了,也在.net界混的风生水起,同时.net也是一个高度封装的框架,作为在wcf食物链最顶端的我们所能做的任务已经简单的不能再简单了, 再简单的话马路上的大妈也能写wcf了 ...

  2. Eclipse "Unable to install breakpoint due to missing line number attributes..."

    Eclipse 无法找到 该 断点,原因是编译时,字节码改变了,导致eclipse无法读取对应的行了 1.ANT编译的class Eclipse不认,因为eclipse也会编译class.怎么让它们统 ...

  3. MyBatis魔法堂:Insert操作详解(返回主键、批量插入)

    一.前言    数据库操作怎能少了INSERT操作呢?下面记录MyBatis关于INSERT操作的笔记,以便日后查阅. 二. insert元素 属性详解   其属性如下: parameterType  ...

  4. TYPESDK手游聚合SDK服务端设计思路与架构之三:流程优化之订单保存与通知

    经过前两篇文字的分析与设计,我们已经可以搭建出一个能够支持多游戏多渠道的聚合SDK服务端,但这只是理想化状态下的一个简化模型.如果接入渠道的逻辑都是按照理想化的简化过程来构建,那么对于支付的请求,我们 ...

  5. Android 手机卫士7--黑名单拦截

    1,黑名单数据库创建 三个字段(_id 自增长字段 phone 黑名单号码 mode 拦截类型) 创建表的sql语句 create table blacknumber (_id integer pri ...

  6. 原生JS实战:写了个一边玩游戏,一边记JS的API的游戏

    本文是苏福的原创文章,转载请注明出处:苏福CNblog:http://www.cnblogs.com/susufufu/p/5878913.html 本程序[一边玩游戏,一边记JS的API]是本人的个 ...

  7. jQuery flickity 滑动触屏

    flickity是一款自适应手机触屏滑动插件,它的API参数很丰富,包括对齐方式.循环滚动.自动播放.是否支持拖动.是否开启分页.是否自适应窗口等. 在线实例 实例演示 使用方法 <div cl ...

  8. iOS 开发 -----公司测试打包上传流程

    打包iOS应用程序 如果想要将做的iOS应用程序安装到自己的iOS设备上测试.或者安装到别人的iOS设备上,或者想发布到App Store中,先要给应用签名.签名就要有证书,这就需要申请证书的过程了. ...

  9. prompt() 方法,弹框带输入框

    prompt() 有alert的风格,却带着输入框,这是怎么实现的呢? 语法 prompt(text,defaultText) 参数 描述 text 可选.要在对话框中显示的纯文本(而不是 HTML ...

  10. CAS Client集群环境的Session问题及解决方案

    [原创申明:文章为原创,欢迎非盈利性转载,但转载必须注明来源] 之前写过一篇文章,介绍单点登录的基本原理.这篇文章重点介绍开源单点登录系统CAS的登录和注销的实现方法.并结合实际工作中碰到的问题,探讨 ...