Godot C#,Nuget软件包Newtonsoft无法构建

问题描述

我有一个项目,在家工作正常,但是由于某种原因,我的工作PC出现错误。 这是摘要。

我已经安装了.net 4.7开发人员工具 我已经安装了最新的Mono

然后我重新启动了PC

C#项目,并将Nuget添加到.csproj文件中:

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

我有一个使用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);
    }
}

我跑了nuget restore 然后,我构建了项目msbuild

然后我尝试从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?)

正如我所说,这在家里的PC上可以100%正常运行,所以不确定我是否错过了工作PC的任何一步。

编辑

从输出日志中:

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.

解决方法

我找到了答案。

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

构建工具设置为dotnet CLI

此操作无效,因此更改为MSBUILD (VS Build Tools)即可正常工作。

,

正如上面 Perry Qian-MSFT 所提到的,在从 Nuget 添加库之后 我必须在 Visual Studio 中构建解决方案,然后才能从 Godot 运行该项目。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...