运行MGCB报错、编辑器异常,MonoGame模板安装失败(macOS Sonoma+VS Code)
问题描述
环境
- macOS Sonoma 系统
- VS Code 开发 MonoGame 项目
打开content.mgcb时的NuGet错误
输出窗口出现以下错误:
Users/<name>/Desktop/code/games/monogame/MyGame/MyGame.csproj : warning NU1803: You are running the 'restore' operation with an 'HTTP' source, 'http://teamcity.monogame.net/guestAuth/app/nuget/feed/_Root/default/v3/index.json'. Non-HTTPS access will be removed in a future version. Consider migrating to an 'HTTPS' source. [/Users/<name>/Desktop/code/games/monogame/MyGame/MyGame.sln] /usr/local/share/dotnet/sdk/8.0.100/NuGet.targets(156,5): error : Unable to load the service index for source http://teamcity.monogame.net/guestAuth/app/nuget/feed/_Root/default/v3/index.json. [/Users/<name>/Desktop/code/games/monogame/MyGame/MyGame.sln] /usr/local/share/dotnet/sdk/8.0.100/NuGet.targets(156,5): error : Network is unreachable (teamcity.monogame.net:80) [/Users/<name>/Desktop/code/games/monogame/MyGame/MyGame.sln] /usr/local/share/dotnet/sdk/8.0.100/NuGet.targets(156,5): error : Network is unreachable [/Users/<name>/Desktop/code/games/monogame/MyGame/MyGame.sln]
编辑器异常与闪退
安装MonoGame模板时的错误
运行dotnet new --install MonoGame.Templates.CSharp时出现以下错误:
MonoGame.Templates.CSharp (version 3.8.1.303) is already installed, it will be replaced with latest version. MonoGame.Templates.CSharp::3.8.1.303 was successfully uninstalled. Warning: The NuGet sources http://teamcity.monogame.net/guestAuth/app/nuget/feed/_Root/default/v3/index.json are insecure and will not be searched. If you want to include those sources for search, use --force. Error: Failed to load template from /Users/<name>/.templateengine/packages/MonoGame.Templates.CSharp.3.8.1.303.nupkg(/content/content/MonoGame.Application.UWP.CoreApp.CSharp/.template.config/template.json). Details: 'identity' is missing or is an empty string. Success: MonoGame.Templates.CSharp::3.8.1.303 installed the following templates:
解决方案
1. 替换不安全的NuGet源
teamcity.monogame.net的HTTP源已无法访问,且属于不安全协议,需替换为官方HTTPS源:
- 终端执行命令移除旧源:
# 先查看所有源,找到对应teamcity的源名称 dotnet nuget list source # 移除旧源,替换为实际源名称 dotnet nuget remove source "TeamCity MonoGame" - 添加官方NuGet源(若已存在可跳过):
dotnet nuget add source https://api.nuget.org/v3/index.json --name "NuGet.org"
2. 修复模板安装问题
旧模板缓存损坏且依赖不可访问源,执行以下步骤:
- 清理旧模板缓存:
替换rm -rf /Users/<name>/.templateengine/packages/MonoGame.Templates.CSharp*<name>为你的系统用户名。 - 重新安装最新模板,指定官方源:
dotnet new --install MonoGame.Templates.CSharp --nuget-source https://api.nuget.org/v3/index.json
3. 修复项目还原问题
进入项目目录重新执行NuGet还原:
cd /Users/<name>/Desktop/code/games/monogame/MyGame dotnet restore
若项目文件硬编码了teamcity源,打开MyGame.csproj或Directory.Packages.props,移除包含http://teamcity.monogame.net的配置项。
4. 解决VS Code闪退问题
- 关闭VS Code,删除工作区缓存:
rm -rf /Users/<name>/Library/Application\ Support/Code/User/workspaceStorage/ - 更新VS Code及MonoGame相关扩展到最新版本
- 重新打开项目,确认NuGet还原无错误后再进行右键操作
内容的提问来源于stack exchange,提问作者MCB
相关产品推荐
相关产品推荐

