Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a nuget package makes Godot not build #30970

Closed
mmarramarco opened this issue Jul 30, 2019 · 15 comments
Closed

Adding a nuget package makes Godot not build #30970

mmarramarco opened this issue Jul 30, 2019 · 15 comments

Comments

@mmarramarco
Copy link

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

@akien-mga akien-mga added this to the 3.2 milestone Jul 30, 2019
@copygirl
Copy link

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.)

@spoutnickgp
Copy link

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 ?

@copygirl
Copy link

@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.)

@mmarramarco
Copy link
Author

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

@mmarramarco
Copy link
Author

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.

@jasonswearingen
Copy link

related: #15386

@neikeq neikeq modified the milestones: 3.2, 4.0 Jan 1, 2020
@neikeq
Copy link
Contributor

neikeq commented Jan 1, 2020

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.

@jasonswearingen
Copy link

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: #34803 (comment)

@codewing
Copy link

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.

@Wanchai
Copy link

Wanchai commented Jul 17, 2020

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

@codewing
Copy link

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

@Wanchai
Copy link

Wanchai commented Jul 18, 2020

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

@codewing
Copy link

codewing commented Jul 18, 2020

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!

@Wanchai
Copy link

Wanchai commented Jul 18, 2020

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

@akien-mga
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants