.NET跨平台之旅:成功将示例站点升级至ASP.NET Core RC2
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的更多相关文章
- .NET跨平台之旅:将示例站点升级至ASP.NET Core 1.0
北京时间6月28日凌晨,微软发布了 .NET Core 1.0,详见新闻 .NET Core 1.0 正式发布了 ,ASP.NET Core 1.0 也随之一起发布了. 紧跟这次发布,我们将跑在 Li ...
- .NET跨平台之旅:将示例站点升级至 ASP.NET Core 1.1
微软今天在 Connect(); // 2016 上发布了 .NET Core 1.1 ,ASP.NET Core 1.1 以及 Entity Framework Core 1.1.紧跟这次发布,我们 ...
- .NET跨平台之旅:将示例站点从 ASP.NET 5 RC1 升级至 ASP.NET Core 1.0
终于将“.NET跨平台之旅”的示例站点 about.cnblogs.com 从 ASP.NET 5 RC1 升级至 ASP.NET Core 1.0 ,经历了不少周折,在这篇博文中记录一下. 从 AS ...
- .NET跨平台之旅:将示例站点从ASP.NET 5 Beta5升级至Beta7
9月2日,微软发布了ASP.NET 5 Beta7(详见Announcing Availability of ASP.NET 5 Beta7).其中最大的亮点是dnx已经可以完全基于CoreCLR运行 ...
- .NET跨平台之旅:将示例站点升级至 .NET Core 1.1 Preview 1
今天微软发布了 .NET Core 1.1 Preview 1(详见 Announcing .NET Core 1.1 Preview 1 ),紧跟 .NET Core 前进的步伐,我们将示例站点 h ...
- .NET跨平台之旅:将示例站点从ASP.NET 5 Beta7升级至RC1
今天,我们将示例站点(about.cnblogs.com,服务器操作系统是Ubuntu)从ASP.NET 5 Beta7升级到了RC1,在升级过程中只遇到了一个问题. 在运行 dnvm upgrade ...
- .NET跨平台之旅:探秘 dotnet run 如何运行 .NET Core 应用程序
自从用 dotnet run 成功运行第一个 "Hello world" .NET Core 应用程序后,一直有个好奇心:dotnet run 究竟是如何运行一个 .NET Cor ...
- .NET跨平台之旅:博问站点迁移至ASP.NET Core on Linux并发布上线
Powered by ASP.NET Core on Linux! 我们全站的 .NET Core 迁移工作如火如荼,这是我们今年上半年的重要工作. 今天我们终于完成了博问产品(q.cnblogs.c ...
- .NET跨平台之旅:在Linux上以本地机器码(native)运行ASP.NET Core站点
在将“.NET跨平台之旅”示例站点 about.cnblogs.com 从 ASP.NET 5 RC1 升级至 ASP.NET Core 1.0 (博文链接)之后,我们有一个难以抗拒的冲动 —— 体验 ...
随机推荐
- 【转载】C#怎么判断字符是不是汉字
支持并尊重原创!原文地址:http://jingyan.baidu.com/article/2c8c281deb79ed0008252af1.html 判断一个字符是不是汉字通常有三种方法,第1种用 ...
- "检索COM类工厂中 CLSID为 {00024500-0000-0000-C000-000000000046}的组件时失败,原因是出现以下错误: 80070005" 问题的解决
一.故障环境 Windows 2008 .net 3.0 二.故障描述 调用excel组件生成excel文档时页面报错.报错内容一大串,核心是"检索COM类工厂中 CLSID为 {000 ...
- C# - Networkcomms
来自英国的用C#语言编写的开源的TCP/UDP网络通信框架,简单方便,性能稳定. 参考: NetworkComms官网: NetworkComms通信框架中文网: 介绍开源的.net通信框架: Ne ...
- shiro实现session共享
session共享:在多应用系统中,如果使用了负载均衡,用户的请求会被分发到不同的应用中,A应用中的session数据在B应用中是获取不到的,就会带来共享的问题. 假设:用户第一次访问,连接的A服务器 ...
- 推荐书单(转自GITHUB)
Skip to content PersonalOpen sourceBusinessExplore Sign upSign in PricingBlogSupport This reposito ...
- jquery操作表格 合并单元格
jquery操作table,合并单元格,合并相同的行 合并的方法 $("#tableid").mergeCell({ cols:[X,X] ///参数为要合并的列}) /** * ...
- centos 域名硬解析(linux)
centos做硬解析跟Windows一样修改一个文件. 具体文件为:/etc/hosts.修改命令: vi /etc/hosts 格式个Windows也一样的.
- 一步步学习 Spring Data 系列之JPA(二)
继上一篇文章对Spring Data JPA更深( )一步剖析. 上一篇只是简单的介绍了Spring Data JPA的简单使用,而往往在项目中这一点功能并不能满足我们的需求.这是当然的,在业务中查询 ...
- Jsp的九个内置对象
一.什么是内置对象?在jsp开发中,会频繁使用到一些对象.例如HttSession,ServletContext,HttpServletRequest.如果我们每次要使用这些对象都去创建这些对象,就会 ...
- Sybase_游标
本章将介绍如何在Sybase下使用游标 因业务需要,要批量处理一些数据,sql需要用到循环,所以要使用游标,我写了一个简单的游标,sql如下 DECLARE my_Cursor CURSOR FOR ...