Godot: Adding a nuget package makes Godot not build

Created on 30 Jul 2019  路  15Comments  路  Source: godotengine/godot

Godot version: 3.1.1-stable-mono-win64

OS/device including version:windows 10

Issue description:Godot doesn't include nuget package, and throw an error on build.

Steps to reproduce: Make any C# project. Attach a script to a node. In VS Code, add a nuget package (Using nuget, or by hand.), and restore the project. Try to build. You get :

ERROR: generate_scripts_metadata: Method/Function Failed, returning: FAILED At: modules/mono/editor/csharp_project.cpp:155 ERROR: editor_build_callback: Condition ' metadata_err != OK ' is true. returned: false At: modules/mono/editor/godotsharp_builds.cpp:383 ERROR: call_build: A Godot Engine build callback failed. At: editor/editor_node.cpp:4666

If you remove the project, and restore again, you get no error. Build successful.

In case it's relevant, i was trying to add Newtonsoft.json, latest version to this day (12.0.2).
I tried another version
I tried targetting another framework.
I tried adding the definition to the packagereference inside the .csproj (sorry, I tried that two days ago, and I can't find it again...)
Nothing works, i'm beat, and it's been two days of searching already.... any ideas?

Minimal reproduction project: Minimal test project. Just open & build.
test.zip

bug mono

Most helpful comment

It would seem this is due to an unsupported format in the package reference you added to your csproj file. Workaround:
The syntax you used seems to cause the issue:
<PackageReference Include="Newtonsoft.Json" Version="12.0.2"/>
But using the alternate syntax seems to properly be interpreted by Godot and does not prevent the build:

<PackageReference Include="Newtonsoft.Json">
<Version>12.0.2</Version>
</PackageReference>

Maybe this is due to a parsing error when godot reads the csproj ?

All 15 comments

I just wanted to point out that this happened to me too. I added the System.ValueTuple package to be able to use tuple syntax in my C# code and Godot failed running the project with the same error.

(Oddly enough, adding the package reference, running nuget restore, then removing the reference from the .csproj, allows me to build the project and use tuple syntax.)

It would seem this is due to an unsupported format in the package reference you added to your csproj file. Workaround:
The syntax you used seems to cause the issue:
<PackageReference Include="Newtonsoft.Json" Version="12.0.2"/>
But using the alternate syntax seems to properly be interpreted by Godot and does not prevent the build:

<PackageReference Include="Newtonsoft.Json">
<Version>12.0.2</Version>
</PackageReference>

Maybe this is due to a parsing error when godot reads the csproj ?

@spoutnickgp Indeed that fixes the issue for me. It's a little unfortunate that Godot prints out quite non-descriptive errors for these, though. I also ran into another parsing error (this time in a .cs file, however) it doesn't like either which had a similarly unhelpful error. (I should create an issue for that.)

I just reopened this issue to see where it was at, i'll make sure to try your work around tonight @spoutnickgp

Nevermind. Tried the work around, and despise building correctly, I can't seem to be able to use the library (missing using directive or assembly reference). I tried several thing, notably adding the package nuget both with the nuget package manager, or the dotnet command line. Neither worked.

What causes this bug is that we're using Mono's own Microsoft.Build assemblies, which are outdated and very limited.
The official Microsoft.Build NuGet packages were recently changed to the MIT license, so we should be able to use them now. But there's no time to do that for 3.2. I'm moving the milestone to 4.0. We can always cherry-pick the changes in 3.2.1.

To anyone with this problem, beware: do not use dotnet restore, that seems to corrupt the .csproj in some way (I think CRLF or BOM tweaks).

download nuget.exe and do nuget restore instead.

I stumbled across this while trying to get Tuples working: https://github.com/godotengine/godot/issues/34803#issuecomment-570752688

I'm adding Tomlyn with:

<PackageReference Include="Tomlyn">
  <Version>0.1.2</Version>
</PackageReference>

Then I use nuget restore and msbuild /t:restore but godot still gives me build errors.
In the Rider IDE it works but I would love to use the editor aswell.

The doc is pretty misleading on this.

  1. you need the good formatting for package ref
  2. you need nuget to use nuget restore
  3. DON'T BUILD WITH DOTNET CLI!!!

In the editor settings use: General -> Mono -> Builds -> Build Tool: MSBuild (VS Build Tools) if on Windows or MSBuild (Mono) for other platforms.

Big thanks to this article:
https://medium.com/@domresc/ep-1-installation-of-godot-engine-and-configuration-of-a-development-environment-for-c-4c051c209bfb

What to you mean with "you need the good formatting for package ref"?

The one you mentioned, not the one in the doc.

I think the docs are up to date, arent they? At least this looks similar to what I've got.
Using NuGet packages in Godot

In the editor settings use: General -> Mono -> Builds -> Build Tool: MSBuild (VS Build Tools) if on Windows or MSBuild (Mono) for other platforms.

That part did the trick for me. Thanks a lot!

You're welcome.
For the package reference thing, it just has been updated. Now it's good.

Fixed by #40595 (master) and #41408 (3.2).

Was this page helpful?
0 / 5 - 0 ratings