Can't open MGCB editor

Whenever i double tap Content.mgcb, nothing happens, and if I type “dotnet mgcb-editor” in terminal it says:

"Could not execute because the specified command or file was not found.
Possible reasons for this include:

  • You misspelled a built-in dotnet command.
  • You intended to execute a .NET program, but dotnet-mgcb-editor does not exist.
  • You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH."

Not sure as to why as I have a freshly installed VS 2022 and the Monogame extension, everything the website states that you need for creating in Monogame.
Any help is appreciated!

Assuming you are using 3.8.1, have you tried following these steps?

I did do all of this, but it sadly didn’t fix the issue.
However I copied the old MGCB editor .exe file from my old PC and it does work, at least for now.

To anyone else having this issue.

I ran the following command in power shell, and after that i could open MGCB in visual studio

dotnet tool install -g dotnet-mgcb

2 Likes

I had this issue too.

I was loading v3.8.0 projects into a v3.8.1 install unknowingly, as I was using a new Windows 11 laptop with everything (Visual Studio, MonoGame, etc.) freshly installed. So, I was a bit lost.

My solution: I tried a new project with MonoGame v3.8.1 and MGCB loads as it should. My intended solution is to create a new project and import all my old project content. LEM’s solution above should be the same, only it’s performed manually. My solution is manual too, I suppose!

I have same issue, I managed to solve the problem by manually modifying the project file in one computer and checked in to source control. but when I try to open the same project in another computer, I get this error:
Could not execute because the specified command or file was not found.
Possible reasons for this include:

  • You misspelled a built-in dotnet command.
  • You intended to execute a .NET program, but dotnet-dotnet-mgcb does not exist.
  • You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.

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

  1. 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
  2. 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"
      ]
    }
  }
}
  1. 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>
  1. 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

  1. 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
  2. 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.

6 Likes

This was awesome, thanks so much for that in depth fix. My team and I have been struggling with this, I was having my artists and audio folks editing the content xml file directly, which was not popular for them lol.

Not only did you provide the fix, but you explained it as well. Thanks!

1 Like