10

ABP Framework 手动升级指南:从6.0.1升级到7.0.0 - iEricLee

 1 year ago
source link: https://www.cnblogs.com/YGYH/p/17045923.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

ABP 7.0.0 正式版已经发布,ABP-Framework-All-In-One 项目同步升级。

LeptonX Lite Theme 目前还没有包含在源码解决方案中,还是以 Nuget 包提供,目前已经更新到 2.0.0

ABP 7.0.0 最大的变化是提供 OpenIddict 应用模块,用于替换 IdentityServer 应用模块。IdentityServer 功能强大,经过多个版本迭代,在 ABP Framework 中也足够稳定,只要官方继续维护该应用模块,可以不用着急切换到 OpenIddcit 。

本文记录从 6.0.1 升级到 7.0.0 的详细过程及注意事项。

第一步:更新 ABP Framework 源码

下载最新版 ABP Framework 源码 7.0.0 到解决方案根目录,将原 abp 目录打包备份,删除该目录,然后将 abp-7.0.0 并解压重命名为 abp ,实现框架源码更新到最新。

第二步:更新 .NET 版本

该版本是跟随 .NET 7 发布之后的升级版,所以 .NET 需要升级到 7 。如果是 Dcoker 部署,需要升级镜像中采用的 SDK 版本。

查看已安装的 .NET 版本,在终端执行命令 dotnet --list-sdks

6.0.400 [/usr/local/share/dotnet/sdk]
7.0.100 [/usr/local/share/dotnet/sdk]

修改解决方案中 global.json 文件

{
  "sdk": {
    "version": "7.0.100"
  }
}

升级项目目标框架

项目目标框架 TargetFramework 如果为 netstandard2.0 ,不需要升级目标框架,与 .NET 7 兼容。

目标框架为 net6.0 ,都必须升级到 net7.0

找到应用程序项目文件 .csproj 修改:

- <TargetFramework>net6.0</TargetFramework>
+ <TargetFramework>net7.0</TargetFramework>

src 目录中包含 11 个项目,test目录中包含 5 个项目,逐一检查修改。

升级程序集版本

解决方案中还有部分项目(srctest 目录中的项目)中的程序集直接基于 Nuget 包引用,所引用的程序集版本应该与 ABP Framework源码项目(abp 目录中的项目)保持版本一致。

src 目录项目程序集版本升级列表:

  • Serilog.AspNetCore 4.1.0 -> 5.0.0

  • Serilog.Sinks.Async 1.4.0 -> 1.5.0

  • Microsoft.AspNetCore.Authentication.JwtBearer 5.0.* -> 7.0.0

  • Microsoft.AspNetCore.DataProtection.StackExchangeRedis 5.0.* -> 7.0.0

  • Volo.Abp.AspNetCore.Mvc.UI.Theme.LeptonXLite 1.0.0-beta.3 -> 2.0.0-*

  • Microsoft.EntityFrameworkCore.Tools 5.0.12 -> 7.0.1

  • Microsoft.Extensions.FileProviders.Embedded 6.0.5 -> 7.0.0

  • Volo.Abp.AspNetCore.Mvc.UI.Theme.LeptonXLite 1.0.0-beta.3 -> 2.0.0

  • Serilog.Extensions.Logging 3.0.1 -> 3.1.0

  • Serilog.Sinks.Async 1.4.0 -> 1.5.0

  • Serilog.Sinks.File 4.1.0 -> 5.0.0

  • Serilog.Sinks.Console 3.1.1 -> 4.1.0

test 目录测试项目程序集版本升级类表:

  • Microsoft.NET.Test.Sdk 16.9.1 -> 17.2.0
  • Microsoft.Extensions.Hosting 5.0.* -> 7.0.0
  • Microsoft.Extensions.Http.Polly 5.0.* -> 7.0.0
  • NSubstitute 4.2.2 -> 4.3.0
  • Shouldly 4.0.3 无需升级
  • xunit 2.4.1 无需升级
  • xunit.extensibility.execution 2.4.1 无需升级
  • xunit.runner.visualstudio 2.4.3 -> 2.4.5

第三步:编译解决方案

执行 dotnet build 编译整个解决方案,编译成功。如果存在警告或错误,检查程序集版本是否设置正确。

第四步:更新数据库结构

升级 dotnet-ef 工具

dotnet tool update --global dotnet-ef

工具 dotnet-ef 升级到当前最新版本 7.0.1

执行命令生成数据迁移脚本:

cd 'src/AbpClub.EntityFrameworkCore'
dotnet ef migrations add UpdateSeven

需要在数据库中新增四张表:

  • AbpFeatureGroups 功能组表
  • AbpFeatures 功能表
  • AbpPermissionGroups 权限组表
  • AbpPermissions 权限表

这四张表用于功能和权限的持久化,以支持动态功能和动态权限。

CmsPages 表中新增列 IsHomePage ,标识是否是主页

详细的数据库结构的改动,可以查看 AbpClub.EntityFrameworkCore 项目中 Migrations 目录下的 xxxxx_UpdateSeven 类。

接下来,执行 dotnet ef database update 将数据迁移脚本更新到数据库。

第五步:升级前端包

AbpClub.Web 项目中找到包配置文件 packages.json,将@abp为前缀的所有NPM包升级到最新版本号。

{
  "version": "1.0.0",
  "name": "abpclub",
  "private": true,
  "dependencies": {
    "@abp/aspnetcore.mvc.ui.theme.leptonxlite": "~1.0.0",
    "@abp/cms-kit": "6.0.1",
    "@abp/docs": "6.0.1",
    "@abp/jstree": "6.0.1",
    "@abp/tui-editor": "6.0.1",
    "@abp/uppy": "6.0.1",
    "@abp/virtual-file-explorer": "6.0.1",
    "slugify": "1.6.5",
    "tui-code-snippet": "2.3.3"
  }
}
{
  "version": "1.0.0",
  "name": "abpclub",
  "private": true,
  "dependencies": {
    "@abp/aspnetcore.mvc.ui.theme.leptonxlite": "~2.0.0",
    "@abp/cms-kit": "7.0.0",
    "@abp/docs": "7.0.0",
    "@abp/jstree": "7.0.0",
    "@abp/tui-editor": "7.0.0",
    "@abp/uppy": "7.0.0",
    "@abp/virtual-file-explorer": "7.0.0",
    "slugify": "1.6.5",
    "tui-code-snippet": "2.3.3"
  }
}

slugifytui-code-snippet 没有新版本,无需升级。

终端工具导航到 Web 项目所在目录,然后执行 abp install-libs 更新包引用。

除了 Web 项目,别忘记将 IdentityServer 项目按照同样的方式进行升级。

{
  "version": "1.0.0",
  "name": "my-app-identityserver",
  "private": true,
  "dependencies": {
    "@abp/aspnetcore.mvc.ui.theme.leptonxlite": "~2.0.0"
  }
}

第六步:功能测试

分别启动 IdentityServer HttpApi.Host 以及 Web 项目,测试应用中的功能是否都正常。

6.0.1 版本中存在的问题,在当前版本中已经修复:访问CMS菜单下除评论外的其他6个页面已经不会抛出异常。

  • 博客:https://localhost:44397/Cms/Blogs
  • 博客帖子:https://localhost:44397/Cms/BlogPosts
  • 菜单:https://localhost:44397/Cms/Menus/Items
  • 页面:https://localhost:44397/Cms/Pages
  • 标签:https://localhost:44397/Cms/Tags

查看源码,已经在 /Themes/LeptonXLite/Layouts/Application.cshtml 页面中修复了该Bug,设置 content_toolbar Section 为非必要渲染。

修复方式:

@await RenderSectionAsync("content_toolbar", false)

升级成功!目前的感受是,版本的稳定性进一步增强了。


本文已收录到《ABP Framework 极速开发》


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK