在 Visual Studio 2019 年创建 Monogame C# 项目时出现错误 MSB3073

Error MSB3073 when creating a Monogame C# project in Visual Studio 2019

所以我试图在 Visual Studio 2019 中使用 C# 简单地创建一个新的 Monogame 项目,并且每次我创建一个新项目时,都会出现以下错误:

Error MSB3073 - The command "dotnet C:\Users\<name>\.nuget\packages\monogame.content.builder.task.8.0.1641\build\..\tools\netcoreapp3.1\any\mgcb.dll /quiet /@:"E:\Programming\Locally-stored projects\C Family\C#\Monogame -OxygOS\Game1\Game1\Content\Content.mgcb" /platform:DesktopGL /outputDir:"E:/Programming/Locally-stored projects/C Family/C#/Monogame - OxygOS/Game1/Game1/Content/bin/DesktopGL/Content" /intermediateDir:"E:/Programming/Locally-stored projects/C Family/C#/Monogame - OxygOS/Game1/Game1/Content/obj/DesktopGL/Content" /workingDir:"E:/Programming/Locally-stored projects/C Family/C#/Monogame - OxygOS/Game1/Game1/Content/"" exited with code 1. Game1   C:\Users\<name>\.nuget\packages\monogame.content.builder.task.8.0.1641\build\MonoGame.Content.Builder.Task.targets    138 

项目中唯一的文件是作为 Monogame 跨平台模板的一部分自动创建的文件。

我已经查看了 Google 和 Stack Overflow,虽然有答案,但我还没有找到对我有帮助的答案。

如果我在创建 post 时搞砸了,我深表歉意,这是我的第一个 Stack Overflow 问题 :D 我可能在某个地方搞砸了格式,如果有的话,请提前道歉。

使用终端创建项目(然后在 Visual Studio 中打开它们)是更好的方法。 Monogame 社区发布项目的 NuGet 模板比发布 Visual Studio 的插件要方便得多,因此可以安全地假设 Monogame 不会随时发布 Visual Studio 的此类插件很快。

确保您已安装 dotnet-sdk 并且通过执行上述所有步骤 here 安装了 Monogame 工具,包括最后两个脚本

dotnet tool install --global dotnet-mgcb-editor
mgcb-editor --register

dotnet new --install MonoGame.Templates.CSharp

现在使用命令dotnet new查看所有模板。您可能会看到类似

的输出

Templates                                                   Short Name               Language          Tags
------------------------------------------------------      -------------------      ------------      ----------------------
...
...
MonoGame Android Application                                mgandroid                [C#]              MonoGame
MonoGame Cross-Platform Desktop Application (OpenGL)        mgdesktopgl              [C#]              MonoGame
MonoGame iPhone/iPad Application                            mgios                    [C#]              MonoGame
MonoGame Windows Universal Application (CoreApp)            mguwpcore                [C#]              MonoGame
MonoGame Windows Universal Application (XAML)               mguwpxaml                [C#]              MonoGame
MonoGame Windows Desktop Application (Windows DirectX)      mgwindowsdx              [C#]              MonoGame
MonoGame NetStandard Library                                mgnetstandard            [C#]              MonoGame
MonoGame Pipeline Extension                                 mgpipeline               [C#]              MonoGame
MonoGame Shared Library Project                             mgshared                 [C#]              MonoGame
...
...

Select你要创建的项目,例如

dotnet new mgwindowsdx -o MyGame

这将创建一个文件夹“MyGame”并放置您的游戏代码。您可以使用 Visual Studio.

打开 .csproj 文件