VS2022升级至17.8.0后.NET7多启动项目运行异常求助
升级Visual Studio 2022 Community至17.8.0版本后,原本基于.NET7.0的MAUI和WebApi多启动项目无法正常运行,Visual Studio会错误调用.NET 8.0的SDK目标文件,出现以下警告与错误:
2>C:\Program Files\dotnet\sdk\8.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targets(251,5): 警告 NETSDK1201: 对于面向.NET 8.0及更高版本的项目,指定RuntimeIdentifier默认不再生成自包含应用。若要继续生成自包含应用,请将SelfContained属性设为true或使用--self-contained参数。 2>C:\Program Files\dotnet\sdk\8.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targets(251,5): 警告 NETSDK1201: 对于面向.NET 8.0及更高版本的项目,指定RuntimeIdentifier默认不再生成自包含应用。若要继续生成自包含应用,请将SelfContained属性设为true或使用--self-contained参数。 2>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(4911,5): 警告 MSB3026: 无法将“C:\Users\marco\.nuget\packages\xamarin.firebase.ios.core\8.10.0.3\lib\net6.0-ios15.4\Firebase.Core.resources\GoogleUtilitiesComponents.xcframework\ios-arm64_x86_64-simulator\GoogleUtilitiesComponents.framework\Headers\GoogleUtilitiesComponents-umbrella.h”复制到“bin\Debug\net7.0-ios\iossimulator-x64\Firebase.Core.resources\GoogleUtilitiesComponents.xcframework\ios-arm64_x86_64-simulator\GoogleUtilitiesComponents.framework\Headers\GoogleUtilitiesComponents-umbrella.h”。将在1000毫秒后开始第7次重试。找不到路径的一部分“bin\Debug\net7.0-ios\iossimulator-x64\Firebase.Core.resources\GoogleUtilitiesComponents.xcframework\ios-arm64_x86_64-simulator\GoogleUtilitiesComponents.framework\Headers\GoogleUtilitiesComponents-umbrella.h”。 2>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(4911,5): 警告 MSB3026: 无法将“C:\Users\marco\.nuget\packages\xamarin.firebase.ios.core\8.10.0.3\lib\net6.0-ios15.4\Firebase.Core.resources\GoogleUtilitiesComponents.xcframework\ios-arm64_x86_64-simulator\GoogleUtilitiesComponents.framework\PrivateHeaders\GULCCComponentContainerInternal.h”复制到“bin\Debug\net7.0-ios\iossimulator-x64\Firebase.Core.resources\GoogleUtilitiesComponents.xcframework\ios-arm64_x86_64-simulator\GoogleUtilitiesComponents.framework\PrivateHeaders\GULCCComponentContainerInternal.h”。将在1000毫秒后开始第7次重试。找不到路径的一部分“bin\Debug\net7.0-ios\iossimulator-x64\Firebase.Core.resources\GoogleUtilitiesComponents.xcframework\ios-arm64_x86_64-simulator\GoogleUtilitiesComponents.framework\PrivateHeaders\GULCCComponentContainerInternal.h”。
以下是可行的解决方法:
锁定项目使用的.NET SDK版本
打开每个项目的.csproj文件,在<PropertyGroup>节点中添加或修改以下配置,强制项目使用.NET7 SDK:<PropertyGroup> <TargetFramework>net7.0</TargetFramework> <!-- MAUI项目需确保TargetFrameworks为net7.0-ios/net7.0-android等 --> <RollForward>Disable</RollForward> <SDKVersion>7.0.404</SDKVersion> <!-- 替换为本地已安装的.NET7 SDK具体版本 --> </PropertyGroup>可通过执行
dotnet --list-sdks命令查看本地已安装的.NET7 SDK版本。用global.json锁定解决方案SDK版本
在解决方案根目录创建或修改global.json文件,指定整个解决方案优先使用的.NET SDK版本:{ "sdk": { "version": "7.0.404", "rollForward": "disable" } }保存后重启Visual Studio,解决方案会自动使用指定的.NET7 SDK。
调整Visual Studio默认SDK设置
打开Visual Studio的工具 > 选项 > 项目和解决方案 > .NET Core,在“默认.NET Core SDK版本”下拉菜单中选择已安装的.NET7 SDK版本,重启VS后生效。处理NETSDK1201警告
锁定SDK版本后该警告会自动消失。若仍存在,可在项目.csproj的<PropertyGroup>中明确设置自包含属性:<PropertyGroup> <SelfContained>true</SelfContained> <!-- 根据项目需求设置true或false --> </PropertyGroup>解决MSB3026文件复制错误
- 手动删除项目的
bin和obj文件夹; - 清理NuGet缓存:
工具 > NuGet包管理器 > 管理解决方案的NuGet程序包 > 设置 > 清除所有NuGet缓存; - 重新生成解决方案;
- 若问题持续,检查Firebase相关NuGet包是否兼容.NET7,尝试更新至兼容版本或重新安装该包。
- 手动删除项目的
确认多启动项目框架设置
右键解决方案 > 属性 > 启动项目,确认两个项目的启动选项中,目标框架均为.NET7.0,未被切换至.NET8。
内容的提问来源于stack exchange,提问作者Marcos Costa

