0

I have a project that at home is working fine, but for some reason on my work PC is getting an error. Here is the rundown.

I have installed .net 4.7 Developer tools I have installed the latest Mono

I have then restarted my PC

C# project, with a Nuget added to the .csproj file:

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

I have a simple code file that is using Newtonsoft:

using Godot;
using Newtonsoft.Json;

public partial class Node2D : Godot.Node2D
{
    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        //Json serialization. 
        var tempclasss = new TestClass
        {
            testprop1 = 40,
            testprop2 = "meep"
        };
        var serialized = JsonConvert.SerializeObject(tempclasss);
        GD.Print(serialized);
    }
}

I ran nuget restore I then built the project msbuild

I then tried to run the project from Godot

Node2D.cs(2,7): error CS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)

As I said, this works 100% fine on my PC at home, so not sure if I missed a step on my PC at work.

EDIT

From output Log:

Project "CsharpTutorial.sln" (Build target(s)):
    Message: Building solution configuration "Debug|Any CPU".
    Project "CsharpTutorial.csproj" (default targets):
        Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
        Csc: C:\Program Files\dotnet\dotnet.EXE exec "C:\Program Files\dotnet\sdk\3.1.401\Roslyn\bincore\csc.dll" /noconfig /nowarn:1701,1702 /nostdlib+ /errorreport:prompt /warn:4 /define:GODOT_WINDOWS;GODOT_64;GODOT;DEBUG;TOOLS /highentropyva+ /reference:C:\Users\dustb\source\personalRepos\godotlearning\CSharpLearning\.mono\assemblies\Debug\GodotSharp.dll /reference:C:\Users\dustb\source\personalRepos\godotlearning\CSharpLearning\.mono\assemblies\Debug\GodotSharpEditor.dll /reference:C:\Users\dustb\.nuget\packages\microsoft.netframework.referenceassemblies.net47\1.0.0\build\.NETFramework\v4.7\mscorlib.dll /reference:C:\Users\dustb\.nuget\packages\microsoft.netframework.referenceassemblies.net47\1.0.0\build\.NETFramework\v4.7\System.Core.dll /reference:C:\Users\dustb\.nuget\packages\microsoft.netframework.referenceassemblies.net47\1.0.0\build\.NETFramework\v4.7\System.dll /debug+ /debug:portable /optimize- /out:.mono\temp\obj\Debug\CsharpTutorial.dll /subsystemversion:6.00 /target:library /utf8output /langversion:7.3 Properties\AssemblyInfo.cs SayHello.cs ".mono\temp\obj\Debug\.NETFramework,Version=v4.7.AssemblyAttributes.cs"
        Csc: Using shared compilation with compiler from directory: C:\Program Files\dotnet\sdk\3.1.401\Roslyn\bincore
        SayHello.cs(2,7): error CS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\dustb\source\personalRepos\godotlearning\CSharpLearning\CsharpTutorial.csproj]
    Done building project "CsharpTutorial.csproj" -- FAILED.
Done building project "CsharpTutorial.sln" -- FAILED.
Mark Johnson
  • 575
  • 4
  • 20
  • probably this will help you https://stackoverflow.com/questions/11697479/type-or-namespace-name-newtonsoft-could-not-be-found – bthn Aug 18 '20 at 08:53
  • Thank you, I had already read this article. It sadly didn't offer a solution to my issue. Theirs is a deploy issue, mine is a build issue in Godot. – Mark Johnson Aug 18 '20 at 09:06
  • Please try to run `dotnet build` for your new sdk project to check whether it helps or not. – Mr Qian Aug 18 '20 at 10:06
  • have you tried removing newtonsoft from project and then adding it again from nuget? – bthn Aug 18 '20 at 10:26
  • @PerryQian-MSFT dotnet build shows the same error. Tried running `dotnet restore` then `dotnet build`... same error. Bear in mind this is targeting .NET 4.7 running `nuget restore`, then `msbuild` builds fine in the terminal, however Godot still won't run project, claiming Newtonsoft if not found. – Mark Johnson Aug 18 '20 at 11:13
  • @bthn yes, still no joy – Mark Johnson Aug 18 '20 at 11:14
  • Someone else suggesting not using `Node2D` as my classname. This is good advice however changing to a unique name didn't help the issue. – Mark Johnson Aug 18 '20 at 11:15
  • I have no exp with godot but I think you can look this answer for unity https://stackoverflow.com/questions/38084186/json-net-in-unity-throwing-the-type-or-namespace-newtonsoft-could-not-be-foun . The idea is adding newtonsoft.dll to godot project folder then add reference to that dll in visual studio – bthn Aug 18 '20 at 11:22
  • @bthn I would rather get Nuget working on my work PC, it works on my home PC, and it's great to use packages. – Mark Johnson Aug 18 '20 at 11:26
  • @MarkJohnson I got you. Have you checked here: https://docs.godotengine.org/en/stable/getting_started/scripting/c_sharp/c_sharp_basics.html#using-nuget-packages-in-godot . it says you need to run `msbuild /t:restore` – bthn Aug 18 '20 at 11:37
  • @bthn Yes I tried that too – Mark Johnson Aug 18 '20 at 12:15
  • Use JetBrains Rider, and it just works. Demo https://youtu.be/FmaYKONV5NY?t=27 – Ivan Shakhov Aug 18 '20 at 12:32
  • @MarkJohnson which godot version you are using? 3 or 4? – bthn Aug 18 '20 at 12:56
  • @bthn Thank you for your help. Right now I am using 3.2.2. However I have found a solution. – Mark Johnson Aug 18 '20 at 13:06

2 Answers2

2

I have found the answer.

Godot -> Editor -> Editor Settings -> Mono -> Builds

Build Tool was set to dotnet CLI

This was not working, so changed to MSBUILD (VS Build Tools) this is now working.

Mark Johnson
  • 575
  • 4
  • 20
0

As mentioned by Perry Qian-MSFT above, after adding the library from Nuget I had to build the solution in Visual Studio then I was able to run the project from Godot.

cmbarnett87
  • 157
  • 1
  • 5
  • 11