Golden_Eagle
Golden_Eagle

Reputation: 134

Monogame: error MSB3073: The command "dotnet tool restore" exited with code 1

I'm trying to use Monogame on Visual Studio 2022, and when I try to build an empty project, I receive a partial restore error. No solutions presented on Google so far have solved the issue.

    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 ==========

Upvotes: 2

Views: 12001

Answers (5)

Matt Gregory
Matt Gregory

Reputation: 8682

I ran into a similar problem. I downloaded the Monogame templates, made a project and tried to build it, but all I got was the error mentioned in the question. When I ran the command manually in the PMC, it gave me:

PM> dotnet tool restore
dotnet : Package Source Mapping is enabled, but no source found under the specified package ID: dotnet-mgcb-editor. See the documentation for Package Source Mapping at https://aka.ms/nuget-package-source-mapping for more details.
At line:1 char:1
+ dotnet tool restore
+ ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Package Source ...r more details.:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

(I may have done something to trigger this error, which I think is ultimately a VS bug, because I've been messing around with package source mapping lately, but for completely unrelated projects.)

So I go into the NuGet Package Manager, search for "mgcb", it pulls up "dotnet-mgcb", "dotnet-mgcb-editor" and things like that. I click on "dotnet-mgcb-editor". There's a message on that page it pulls up on the right about source mapping and there's a blue Configure link. I click that and it pulls up Options > NuGet Package Manager > Package Source Mappings. I click the Add button. I enter "dotnet-mgcb-editor" as the pattern and checked nuget.org. Hit Add. Hit OK. Tools installed. Project built. It runs.

All that said, I've since deleted that source mapping pattern and it still works, so I have no idea. It's some sort of VS bug, I reckon.

Upvotes: 0

Sajid Ali
Sajid Ali

Reputation: 779

Installing dotnet 7.0 fixed the problem for me. Here is the link to download the version https://dotnet.microsoft.com/en-us/download/dotnet/7.0

Upvotes: 0

edwin
edwin

Reputation: 2841

I ran into this problem because .config/dotnet-tools.json was marked by Windows as unsafe.

Solution: go to the properties of this file and check "Unblock". Then everything worked as expected.

Another solution I found is unblocking the zip file where all files were stored in before extracting the zip file.

Properties dialog with Unblock checkbox at the bottom

Upvotes: 6

Chris Clements
Chris Clements

Reputation: 198

Try restarting your computer. I installed the Monogame Project extensions, created a couple projects and ran into this error. The error disappeared and I can compile debug Monogame Projects.

Upvotes: 0

dudu
dudu

Reputation: 19

I had the same error using vscode to build the project and was able to solve the issue by editing the file .config/dotnet-tools.json with the most recent version of the dotnet-mgcb-editor-windows package 3.8.1.303

My file:

{
  "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"
      ]
    }
  }
}

Upvotes: 0

Related Questions