There has been some confusion as of lately in the MonoGame discord when trying to use the MGCB Editor, and it seems to coming from a google search that points to this thread.
The common problem is that everyone is seeing the response that installing the tool using the -g
flag is the resolution, but that’s actually what’s causing the questions to come up on discord with individuals having the problem.
For future reference from people that google and end up here, I wanted to offer some information that may help. It’s broken down into different sections below.
MGCB Editor
The MGCB Editor, starting with MonoGame 3.8.1, should no longer be installed as a global tool.
When you install the templates to create a new MonoGame project, either through the Visual Studio extension or through the CLI, the MonoGame 3.8.1 templates will create a file in your game project .config/dotnet-tools.json
. If you are not familar with how “tools” work with dotnet, I would suggest reading up on it at .NET tools - .NET CLI | Microsoft Learn
This config file includes all of the necessary things setup for your project to use a “local” tool. This doesn’t mean that new tool files are downloaded and stored on your computer for every single project you make. NuGet stores packages/tools downloaded to a common directory (%USERPROFILE%\.nuget\packages\
by default on windows).
If you’re coming from the world of web dev and NPM, it doesn’t work like that. It’s not like there’s a local “tools” directory it’s installed to that just wastes space on your computer for every project.
So when you create a new MonoGame 3.8.1 project, it should do a NuGet restore automatically to ensure the tooling is setup, but you can always manually NuGet restore in Visual Studio or run the dotnet restore
command from the project directory.
Resolving mgcb-editor command could not be found
Issue
Following these steps will generally resolve the issue for you. You can also find this information in the document linked by @LEM above at https://github.com/MonoGame/MonoGame/blob/develop/Documentation/articles/migrate_38.md
- Ensure you do not have the tool installed as a global tool. You can do this by just running the command
dotnet tool uninstall mgcb-editor -g
- Ensure in your project directory (this is the directory with the
.csproj
file) that you have a directory called .config
and that directory has the dotnet-tools.json
file. If it does not have this directory and/or file, you perform the following:
2.1. Run the command dotnet new tool-manifest
from the project directory. This will create the .config/dotnet-tools.json
file.
2.2. Open that dotnet-tools.json
file and replace the contents with the following: Note: at the time of this writing, the current version is 3.8.1.303
as shown in the contents below. This version should match the version number of MonoGame that you are using, so edit accordingly.
{
"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"
]
}
}
}
- Ensure the following is in your
.csproj file
<Target Name="RestoreDotnetTools" BeforeTargets="Restore">
<Message Text="Restoring dotnet tools" Importance="High" />
<Exec Command="dotnet tool restore" />
</Target>
- Assuming you have the
.config/dotnet-tools.json
file in your project directory, and that you don’t have the tool installed globally and that the contents of the tool file are as shown above, execute dotnet restore
from your project directory. This should download the tool.
But What If I Want It As A Global Tool?
There really is no reason to have it as a global tool. DotNET tools are cached in the NuGet packages directory as I mentioned earlier, so it’s not like you’re using additional disk space for every project you create. The other advantage to having it as a local tool, is the local dotnet-tools.json
manifest file includes the packages for Windows, Mac, and Linux. So if you move your development between environments, you don’t have to worry about ensuring the correct global tool install.
But I hear you, you still want it global. So if you really want it global, against advice and official documentation as linked above by @LEM, then you will need to perform the following
- Install the correct global tool for your platform
1.a Windows: dotnet tool install dotnet-mgcb-editor-windows -g
1.b Mac: dotnet tool install dotnet-mgcb-editor-mac -g
1.c Linux: dotnet tool install dotnet-mgcb-editor-linux -g
- Then to open it, you just run the command
2.a Windows: mgcb-edtior-windows /path/to/Content.mgcb
2.b Mac: mgcb-edtior-mac /path/to/Content.mgcb
2.c Linux: mgcb-edtior-linux /path/to/Content.mgcb
I haven’t tested, nor will I, but I cannot make any guarantee that this will ensure that double-clicking the Content.mgcb
file within Visual Studio opens it correctly when it is installed as a global tool. I do not use Visual Studio, I use VSCode.