如何升级 Blazor Asp.net Identity 脚手架自带的 jQuery ,jQuery Validation, Unobtrusive validation 版本,去掉CDN

 首先来个卸载,安装,升级三部曲,我们升级一下脚手架的版本

dotnet tool uninstall -g dotnet-aspnet-codegenerator
dotnet tool install -g dotnet-aspnet-codegenerator
dotnet tool update -g dotnet-aspnet-codegenerator

然后可以看看安装了哪个版本

dotnet tool list -g

可以看到类型结果

Package Id             Version      Commands
------------------------------------------------
dotnet-aspnet-codegenerator      8.0.1      dotnet-aspnet-codegenerator

 然后我们看看脚手架的具体用法

Usage: aspnet-codegenerator [arguments] [options]

Arguments:
  generator  Name of the generator. Check available generators below.

Options:
  -p|--project             Path to .csproj file in the project.
  -n|--nuget-package-dir   
  -c|--configuration       Configuration for the project (Possible values: Debug/ Release)
  -tfm|--target-framework  Target Framework to use. (Short folder name of the tfm. eg. net46)
  -b|--build-base-path     
  --no-build               

Selected Code Generator: identity

Generator Options:
  --dbContext|-dc      : Name of the DbContext to use, or generate (if it does not exist).
  --files|-fi          : List of semicolon separated files to scaffold. Use the --list-files option to see the available options.
  --listFiles|-lf      : Lists the files that can be scaffolded by using the '--files' option.
  --userClass|-u       : Name of the User class to generate.
  --useSqLite|-sqlite  : Flag to specify if DbContext should use SQLite instead of SQL Server.
  --force|-f           : Use this option to overwrite existing files.
  --useDefaultUI|-udui : Use this option to setup identity and to use Default UI.
  --layout|-l          : Specify a custom layout file to use.
  --generateLayout|-gl : Use this option to generate a new _Layout.cshtml

具体参考官网

然后,关键的东西来了,如果你的项目是 .net 7 创建的,请务必要把 Microsoft.AspNetCore.Identity.UI 这个库升级到 7.0.16

这个库版本下的 jquery.validate.min.js 已经升级到了 v1.19.5
然后用 脚手架 生成一个关键的 Blazor 页面,需要先 cd 到项目路径,然后执行命令,以我为例,项目路径是 “D:\IloveCode\acl\CTC”

PM> cd D:\IloveCode\acl\CTC
PM> dotnet aspnet-codegenerator identity --useDefaultUI
Building project ...
Finding the generator 'identity'...
Running the generator 'identity'...
RunTime 00:00:12.48

特别要加上 参数 --useDefaultUI,这时候会在项目下生成这个文件

修改一下这个文件里面的路径,对比如下,右边是修改好的,替换CDN为本地路径

这个时候我们把网站发布,并运行起来

可以看到,之前默认的CDN已经没有了。由于 /Identity/lib/xxx 这个路径是编译运行动态生成,发布时也是动态生成的,所以我们在编译的时候不能替换他的 jquery, jquery.validate, jquery.validate.unobtrusive 这些库,因为这些库来自 Microsoft.AspNetCore.Identity.UI 这个库的内嵌资源文件,所以要想升级这些 js 库的版本,只能去升级 Microsoft.AspNetCore.Identity.UI ,比如我这次就从 3.0 一口气升级到了 7.0.16


上面这是一种升级方式,还有一种方法就是发布以后,用你下载的js文件去覆盖掉这些文件,就是 wwwroot 下的 Identity 下的 lib 这些文件,包括 bootstrap 都可以覆盖升级。当然这种方法可以非常彻底的解决问题,不会依赖  Microsoft.AspNetCore.Identity.UI 版本,想用哪个js版本手动覆盖就行了,缺点就是每次发布以后都要手动覆盖一次,比较费事。

  • 6
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值