我尝试在 Visual Studio 2022 上使用 Monogame,当我尝试构建空项目时,收到部分恢复错误。到目前为止,Google 上提出的解决方案还没有解决该问题。
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>
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>
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>
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 ==========
我遇到这个问题是因为
.config/dotnet-tools.json
被 Windows 标记为不安全。
解决方案:进入该文件的属性并勾选“取消阻止”。然后一切都按预期进行。
我发现的另一个解决方案是在解压 zip 文件之前解锁存储所有文件的 zip 文件。
我在使用 vscode 构建项目时遇到了同样的错误,并且能够通过使用最新版本的 dotnet-mgcb-editor-windows 包 3.8.1.303 编辑文件 .config/dotnet-tools.json 来解决问题
我的文件:
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-mgcb": {
"version": "3.8.1.303",
"commands": [
"mgcb"
]
},
"dotnet-mgcb-editor": {
"version": "3.8.1.303",
"commands": [
"mgcb-editor"
]
},
"dotnet-mgcb-editor-linux": {
"version": "3.8.1.303",
"commands": [
"mgcb-editor-linux"
]
},
"dotnet-mgcb-editor-windows": {
"version": "3.8.1.303",
"commands": [
"mgcb-editor-windows"
]
},
"dotnet-mgcb-editor-mac": {
"version": "3.8.1.303",
"commands": [
"mgcb-editor-mac"
]
}
}
}
尝试重新启动计算机。我安装了 Monogame 项目扩展,创建了几个项目并遇到了此错误。 错误消失了,我可以编译调试 Monogame 项目了。
安装 dotnet 7.0 解决了我的问题。 这是下载版本的链接 https://dotnet.microsoft.com/en-us/download/dotnet/7.0