- 条件编译 #if NET6_0 改为 #if NET7_0 或者 #if NET6_0_OR_GREATER
#if NET6_0_OR_GREATER
using BootstrapBlazor.Components;
#endif
-
项目目标支持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>
- 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>
- 多目标 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>
- BrotliCompressionProviderOptions 提示 (CompressionLevel)4 不正确
builder.Services.Configure<BrotliCompressionProviderOptions>(options =>
{
//options.Level = (CompressionLevel)4;
options.Level = CompressionLevel.Optimal; //改为这个
});
-
库生成提示 ‘xxx.dll’ does not contain an entry point. 项目文件
PropertyGroup
内加入<OpenApiGenerateDocuments>false</OpenApiGenerateDocuments>
-
提示
证书链是由不受信任的颁发机构颁发的
, 链接串后加入;Encrypt=False
-
有编辑过
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 //这句是我项目另外加的
}
}
}
- 库升级 .Net 7.0 后生成提示 Assembly “xxx.dll” does not contain an entrypoint 临时解决办法
在工程项目文件.csproj 添加这行
<PropertyGroup>
...
<OpenApiGenerateDocuments>false</OpenApiGenerateDocuments>
...
</PropertyGroup>
就可以跳过 GenerateOpenApiDocuments 继续生成了
- 升级vs或者装了.Net 7.0后, 工程框架用 net6 的 dotnet watch 出错 'Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly ‘System.Runtime, Version=7.0.0.0’
工程框架
<TargetFramework>net6.0</TargetFramework>
错误
dotnet watch 🚀 Started
Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
File name: 'System.Runtime, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
at System.Reflection.RuntimeAssembly.GetType(QCallAssembly assembly, String name, Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack type, ObjectHandleOnStack keepAlive, ObjectHandleOnStack assemblyLoadContext)
at System.Reflection.RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase)
at System.Reflection.Assembly.GetType(String name, Boolean throwOnError)
at System.StartupHookProvider.CallStartupHook(StartupHookNameOrPath startupHook)
at System.StartupHookProvider.ProcessStartupHooks()
临时解决方案: 工程目录下建立 global.json 文件指定编译框架
{
"sdk": {
"version": "6.0.403"
}
}