Visual Studio 2022中MonoGame项目构建失败:dotnet tool restore报错代码1
解决MonoGame 3.8.1.263项目构建时dotnet-mgcb-editor-windows包找不到的问题
问题说明
在Visual Studio 2022中创建MonoGame空项目后,构建时触发部分还原失败:核心错误为找不到版本3.8.1.263的dotnet-mgcb-editor-windows包,执行dotnet tool restore命令退出代码为1,最终导致项目构建失败。错误日志显示nuget.org仅提供3.8.1.1-develop版本匹配,离线包源无对应版本。
解决方案
1. 修改工具包版本为可用版本
- 定位到项目根目录下的
.config/dotnet-tools.json文件 - 找到
dotnet-mgcb-editor-windows对应的配置条目,将版本号从3.8.1.263替换为nuget.org上存在的3.8.1.1-develop - 保存文件后,执行
dotnet tool restore命令,再重新构建项目
2. 降级MonoGame到稳定正式版
- 在Visual Studio中右键项目,选择「管理NuGet程序包」
- 将
MonoGame.Framework.WindowsDX(或对应平台的框架包)、MonoGame.Content.Builder.Task等相关MonoGame包的版本降级到3.8.1正式版(避开3.8.1.263这个开发预览版) - 同步更新
.config/dotnet-tools.json中所有MonoGame工具包的版本到3.8.1,执行dotnet tool restore后重新构建
3. 手动全局安装兼容工具包
- 打开命令提示符,执行以下命令全局安装可用版本的工具:
dotnet tool install --global dotnet-mgcb-editor-windows --version 3.8.1.1-develop - 安装完成后,删除项目
.config/dotnet-tools.json中dotnet-mgcb-editor-windows的条目(全局工具无需在项目中声明),再尝试构建项目
4. 检查并修复NuGet源配置
- 打开Visual Studio的「工具」->「选项」->「NuGet包管理器」->「包源」,确认nuget.org源处于启用状态
- 执行
dotnet nuget locals all --clear清除NuGet缓存,然后重新执行包还原操作
详细错误日志
Build started... 1>------ Build started: Project: Project1, Configuration: Debug Any CPU ------ 1>C:\Users\johnk\AppData\Local\Temp\denfz23c.23a\restore.csproj : error NU1102: Unable to find package dotnet-mgcb-editor-windows with version (= 3.8.1.263) 1>C:\Users\johnk\AppData\Local\Temp\denfz23c.23a\restore.csproj : error NU1102: - Found 1 version(s) in nuget.org [ Nearest version: 3.8.1.1-develop ] 1>C:\Users\johnk\AppData\Local\Temp\denfz23c.23a\restore.csproj : error NU1102: - Found 0 version(s) in Microsoft Visual Studio Offline Packages 1>Package "dotnet-mgcb-editor-windows" failed to restore, due to Microsoft.DotNet.ToolPackage.ToolPackageException: The tool package could not be restored. 1> at Microsoft.DotNet.Tools.Tool.Install.ProjectRestorer.Restore(FilePath project, PackageLocation packageLocation, String verbosity) 1> at Microsoft.DotNet.ToolPackage.ToolPackageInstaller.InstallPackageToExternalManagedLocation(PackageLocation packageLocation, PackageId packageId, VersionRange versionRange, String targetFramework, String verbosity) 1> at Microsoft.DotNet.Tools.Tool.Restore.ToolRestoreCommand.InstallPackages(ToolManifestPackage package, Nullable`1 configFile) 1>Tool 'dotnet-mgcb' (version '3.8.1.263') was restored. Available commands: mgcb 1>Tool 'dotnet-mgcb-editor' (version '3.8.1.263') was restored. Available commands: mgcb-editor 1>Restore partially failed. 1>Tool 'dotnet-mgcb-editor-linux' (version '3.8.1.263') was restored. Available commands: mgcb-editor-linux 1>Tool 'dotnet-mgcb-editor-mac' (version '3.8.1.263') was restored. Available commands: mgcb-editor-mac 1>C:\Users\johnk\.nuget\packages\monogame.content.builder.task\3.8.1.263\build\MonoGame.Content.Builder.Task.targets(139,5): error MSB3073: The command "dotnet tool restore" exited with code 1. 1>Done building project "Project1.csproj" -- FAILED. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
内容的提问来源于stack exchange,提问作者Golden_Eagle
相关产品推荐
相关产品推荐

