微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决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 运行该项目。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。