互联网网站界面设计 要素,wordpress加友情链接,番禺区网站优化,沈阳学网站制作学校这两天把一个 asp.net core 1.1 的项目迁移到了 asp.net core 2.0 preview 2 #xff0c;在这篇随笔中记录一下。
如果项目在有 global.json 文件#xff0c;需要删除或修改为 .net 2.0 preview 2 的 sdk 版本号。
对于类库项目的 .csproj#xff0c;需要把 TagetFramewo…这两天把一个 asp.net core 1.1 的项目迁移到了 asp.net core 2.0 preview 2 在这篇随笔中记录一下。
如果项目在有 global.json 文件需要删除或修改为 .net 2.0 preview 2 的 sdk 版本号。
对于类库项目的 .csproj需要把 TagetFramework 改为 netstandard2.0 比如
PropertyGroupTargetFrameworknetstandard1.6/TargetFramework AssemblyNameCNBlogs.Identity.ServiceAgent/AssemblyNamePackageIdCNBlogs.Identity.ServiceAgent/PackageId NetStandardImplicitPackageVersion1.6.1/NetStandardImplicitPackageVersion GenerateAssemblyConfigurationAttributefalse/GenerateAssemblyConfigurationAttribute GenerateAssemblyCompanyAttributefalse/GenerateAssemblyCompanyAttribute GenerateAssemblyProductAttributefalse/GenerateAssemblyProductAttribute/PropertyGroup
改为
PropertyGroupTargetFrameworknetstandard2.0/TargetFramework/PropertyGroup
对于单元测试项目TargetFramework 需要改为 netcoreapp2.0 比如
PropertyGroupTargetFrameworknetcoreapp1.1/TargetFrameworkAssemblyNameCNBlogs.Identity.UnitTests/AssemblyNamePackageIdCNBlogs.Identity.UnitTests/PackageId GenerateRuntimeConfigurationFilestrue/GenerateRuntimeConfigurationFiles RuntimeFrameworkVersion1.1.1/RuntimeFrameworkVersion GenerateAssemblyConfigurationAttributefalse/GenerateAssemblyConfigurationAttribute GenerateAssemblyCompanyAttributefalse/GenerateAssemblyCompanyAttribute GenerateAssemblyProductAttributefalse/GenerateAssemblyProductAttribute/PropertyGroup
改为
PropertyGroupTargetFrameworknetcoreapp2.0/TargetFramework/PropertyGroup
对于 web 项目需要该动的地方很多。除了把 TargetFramework 改为 netcoreapp2.0 比如
PropertyGroupTargetFrameworknetcoreapp1.1/TargetFramework PreserveCompilationContexttrue/PreserveCompilationContextAssemblyNameCNBlogs.Identity.Web/AssemblyNameOutputTypeExe/OutputTypePackageIdCNBlogs.Identity.Web/PackageIdRuntimeIdentifierswin10-x64;win8-x64;osx.10.12-x64;ubuntu.14.04-x64/RuntimeIdentifiers PackageTargetFallback$(PackageTargetFallback);dnxcore50;portable-net45win10/PackageTargetFallback RuntimeFrameworkVersion1.1.1/RuntimeFrameworkVersion/PropertyGroup
改为
PropertyGroupTargetFrameworknetcoreapp2.0/TargetFramework/PropertyGroup
还需要
1移除所有对 Microsoft.AspNetCore 的引用
PackageReference IncludeMicrosoft.AspNetCore.Authentication Version1.1.2 /PackageReference IncludeMicrosoft.AspNetCore.Authentication.Cookies Version1.1.2 /PackageReference IncludeMicrosoft.AspNetCore.DataProtection.Extensions Version1.1.2 /PackageReference IncludeMicrosoft.AspNetCore.DataProtection.Redis Version0.1.2 /PackageReference IncludeMicrosoft.AspNetCore.Diagnostics Version1.1.2 /PackageReference IncludeMicrosoft.AspNetCore.Hosting Version1.1.2 /PackageReference IncludeMicrosoft.AspNetCore.Mvc Version1.1.3 /PackageReference IncludeMicrosoft.AspNetCore.Mvc.Razor.ViewCompilation Version1.1.1 /PackageReference IncludeMicrosoft.AspNetCore.Server.IISIntegration Version1.1.2 /PackageReference IncludeMicrosoft.AspNetCore.Server.Kestrel Version1.1.2 /PackageReference IncludeMicrosoft.AspNetCore.Session Version1.1.2 /PackageReference IncludeMicrosoft.AspNetCore.StaticFiles Version1.1.2 /
添加 Microsoft.AspNetCore 的引用
PackageReference IncludeMicrosoft.AspNetCore.All Version2.0.0-preview2-final /
2修改 Authentication 相关的代码
CookieAuthenticationOptions 的命名空间改为 Microsoft.AspNetCore.Authentication.CookiesHttpContext.Authentication.SignInAsync() 改为 HttpContext.SignInAsync() 需要安装 NuGet 包 Microsoft.AspNetCore.Authentication.Abstractions 引用命名空间 Microsoft.AspNetCore.Authentication 。 cookieAuthOptions.Value.AuthenticationScheme 改为 CookieAuthenticationDefaults.AuthenticationScheme
3 针对 BundlerMinifier 的修改
在 asp.net core 2.0 preview 2 的 docker 容器中 build 项目在执行 dotnet bundle 时出现下面的错误
It was not possible to find any compatible framework version
The specified framework Microsoft.NETCore.App, version 1.1.0 was not found.
- Check application dependencies and target a framework version installed at:/
- Alternatively, install the framework version 1.1.0.
这是由于 nuget 包 BundlerMinifier.Core 不支持 .net core 2.0 。github 上签出 BundlerMinifier 的源码已增加了对.net core 2.0的支持自己打包。
升级时不仅要升级 PackageReference 中的 BundlerMinifier.Core 还要升级 DotNetCliToolReference 中的 BundlerMinifier.Core 。
4针对 DataProtection 的修改
Microsoft.AspNetCore.DataProtection.Redis 的 PersistKeysToRedis() 方法不起作用需要改用临时解决方法
services.ConfigureKeyManagementOptions(o {o.XmlRepository new RedisXmlRepository(() redisConn.GetDatabase(), DataProtection-Keys-Cnblogs);
});
详见 PersistKeysToRedis not working in .NET Core 2.0 Preview 2 with Redis 0.1.2
5Startup 的修改
去除构造函数中下面的代码var builder new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile(appsettings.json, optional: true, reloadOnChange: true) .AddJsonFile($appsettings.{env.EnvironmentName}.json, optional: true); builder.AddEnvironmentVariables(); Configuration builder.Build();去除 Configure 方法中下面的代码loggerFactory.AddSerilog(); loggerFactory.AddConsole(Configuration.GetSection(Logging));IConfigurationRoot 改为 IConfigurationpublic Startup(IConfiguration configuration)
{Configuration configuration;
} public IConfiguration Configuration { get; set; }
6Program 的修改
public class Program
{ public static void Main(string[] args){BuildWebHost(args).Run();} public static IWebHost BuildWebHost(string[] args){ return WebHost.CreateDefaultBuilder(args).ConfigureLogging((context, logging) {logging.AddSerilog();}).UseStartupStartup().Build();}
}
完成 web 项目升级后升级所有 NuGet 包删除所有 AssemblyInfo.cs 文件整个升级就完成了。
原文地址http://www.cnblogs.com/dudu/p/7266134.html .NET社区新闻深度好文微信中搜索dotNET跨平台或扫描二维码关注