升级 Net 7 随手笔记 (注意事项以及解决方案) - 持续更新

  1. 条件编译 #if NET6_0 改为 #if NET7_0 或者 #if NET6_0_OR_GREATER
#if NET6_0_OR_GREATER
using BootstrapBlazor.Components;
#endif
  1. 项目目标支持6和7改为<TargetFramework>net6.0;net7.0</TargetFrameworks>,只需要7直接改为<TargetFramework>net7.0</TargetFramework>

    多目标引用库参考

	<ItemGroup Condition="'$(TargetFramework)' != 'net7.0'">
		<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="6.0.0" />
	</ItemGroup>

	<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
		<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="7.0.0" />
	</ItemGroup> 
	<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
	  <PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="6.0.10" />
	  <PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
	</ItemGroup>

	<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
		<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="7.0" />
		<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0" />
	</ItemGroup> 
  1. Maui工程或者库参考目标方案
<TargetFrameworks>netstandard2.0;netstandard2.1;net461;net6.0;net6.0-windows10.0.19041;net6.0-ios;net6.0-maccatalyst;net6.0-android;net7.0;net7.0-windows10.0.19041;net7.0-ios;net7.0-maccatalyst;net7.0-android</TargetFrameworks>
  1. 多目标 net461;net7.0 提示冲突 System.Drawing 存在于 4.0 和 7.0
    <ItemGroup Condition=" '$(TargetFramework)' == 'net7.0' ">
        <PackageReference Include="System.Drawing.Common" Version="7.0.0" />
        <PackageReference Include="Microsoft.Windows.Compatibility" Version="7.0" />
    </ItemGroup> 
  1. BrotliCompressionProviderOptions 提示 (CompressionLevel)4 不正确
            builder.Services.Configure<BrotliCompressionProviderOptions>(options =>
            {
                //options.Level = (CompressionLevel)4;
                options.Level = CompressionLevel.Optimal; //改为这个
            });
  1. 库生成提示 ‘xxx.dll’ does not contain an entry point. 项目文件 PropertyGroup 内加入 <OpenApiGenerateDocuments>false</OpenApiGenerateDocuments>

  2. 提示 证书链是由不受信任的颁发机构颁发的 , 链接串后加入 ;Encrypt=False

  3. 有编辑过 xxx.runtimeconfig.json 文件的同学注意了: 升级了net7,这个文件也要相应的更新. 例如本人就加过这句

"System.Drawing.EnableUnixSupport": true

并且生成 release 特定跳过了复制这个文件 xxx.runtimeconfig.json 倒置发布到 centos后服务无法启动,一直提示

  Unhandled exception. System.IO.FileLoadException: Could not load file or assembly 'System.Runtime, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. 
  The located assembly's manifest definition does not match the assembly reference. (0x80131040)
  File name: 'System.Runtime, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

排查了半天才想起这个文件. 新版默认文件内容为

{
  "runtimeOptions": {
    "tfm": "net7.0",
    "frameworks": [
      {
        "name": "Microsoft.NETCore.App",
        "version": "7.0.0"
      },
      {
        "name": "Microsoft.AspNetCore.App",
        "version": "7.0.0"
      }
    ],
    "configProperties": {
      "System.GC.Server": true,
      "System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
      "System.Reflection.NullabilityInfoContext.IsSupported": true,
      "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false,
      "System.Drawing.EnableUnixSupport": true //这句是我项目另外加的
    }
  }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Densen2014

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值