以前用VS2019,打开新生命NewLife.Core源码没问题,现在升级到VS2022了,却发现编译不了,报错如下:
Error MSB3644 The reference assemblies for .NETFramework,Version=v4.5 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks NewLife.Core C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets 1229
原来VS2022默认不再支持.NET4.5,即使在Visual Studio Installer中也找不到.NET4、.NET4.5、.NET4.5.1的选项。
百度搜索了一下,已经 验证的方法就是手动下载NuGet包(https://www.nuget.org/packages/microsoft.netframework.referenceassemblies.net45),解压缩并复制到VS2022安装目录(如:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5),重启VS2022即可。
同样的,如果有需要支持.NET 4的,就按照上述方法到这个地址下载相应的nuget包:NuGet Gallery | Microsoft.NETFramework.ReferenceAssemblies.net40 1.0.3