将 C# dll 与 G-WAN 结合使用

Using C# dll with G-WAN

我的目标是在 G-WAN 上应用创建 运行 并连接到 Azure 存储的脚本。因此,为了实现这一点,我首先尝试如何在 G-WAN 中将 link dll 转换为 C# 脚本,但我遇到了这个错误

Error: test.cs
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Package TestGwanLibrary was not found in the pkg-config search path.
Perhaps you should add the directory containing `TestGwanLibrary.pc'
to the PKG_CONFIG_PATH environment variable
No package 'TestGwanLibrary' found
error CS8027: Error running pkg-config. Check the above output.

1|// pragma link TestGwanLibrary
2|using System;
3|using System.Collections.Generic;
4|
5|public class Program
6|{
7|    public static int Main (string[] args)
8|    {


To run G-WAN, you must fix the error(s) or remove this Servlet



Error(s) in testdll.cs

我的C#servlet脚本如下

// pragma link TestGwanLibrary
using System;
using System.Collections.Generic;

public class Program
{
    public static int Main (string[] args)
    {
        Console.WriteLine ("Running test.cs");
        TestGwanClass2.PrintToConsole2 ("ptc2 test");
        return 200;
    }
}

按照 G-WAN FAQ 中的说明,我已将 GameCloudLibrary.dll 放入

root/gwan_linux64-bit/libraries/cs/dll

但是,当我 运行 gwan 时出现以下错误。我还尝试添加一个指向

的 MONO_PATH
/root/gwan_linux64-bit/libraries/cs/dll

但上面的错误仍未解决

我目前的设置如下

下面是 class 库,使用 .NET Standard 2.0 使用系统;

namespace TestGwanLibrary
{
    public class TestGwanClass
    {
        public static void PrintToConsole (string message)
        {
            Console.WriteLine ("PrintToConsole : " + message);
        }
    }
}

public class TestGwanClass2
{
    public static void PrintToConsole2 (string message)
    {
        Console.WriteLine ("PrintToConsole2 : " + message);
    }
}

我不确定我应该如何处理这个错误。有人,请告诉我我所缺少的东西!

我们使用 G-WAN C# 脚本已经有一段时间了(我们使用 G-WAN 的主要目标是 C 脚本)并且 C# 运行时可能已经以破坏事物的方式发展(Java, Objective-C、D 和其他语言一直导致这种向后兼容性问题。

我想,在某些人看来,这就是 "unstoppable march of progress"

John(上文)可能建议将 G-WAN C# 库的功能嵌入到 C# 脚本中(或作为 G-WAN /libraries 中的源代码文件夹)- 除非您的库很大并且被数百个脚本使用,否则不会有任何损失(速度、内存)。

但是如果您面临这种运行时开销问题,那么我建议您使用更简单的运行时,例如 ANSI C。这也将有利于可扩展性。

第一期:缺少 TestGwanLibrary.pc。

Package TestGwanLibrary was not found in the pkg-config search path.
Perhaps you should add the directory containing `TestGwanLibrary.pc'
to the PKG_CONFIG_PATH environment variable
No package 'TestGwanLibrary' found
error CS8027: Error running pkg-config. Check the above output.

为了解决这个问题,我在 /usr/lib64/pkgconfig 中创建了 TestGwanLibrary.pc,内容如下所示。

Name: TestGwanLibrary
Description: Test dll for using C# in G-WAN
Version: 1.0.0.0
Libs: -r:/root/gwan_linux64-bit/libraries/cs/dll/TestGwanLibrary.dll

我试过将 TestGwanLibrary.pc 放在 /usr/lib/pkgconfig 和 /usr/share/pkgconfig 中,但都没有用,所以我猜 gwan binary 只在 /usr/lib64/pkgconfig 中搜索包。

在 TestGwanLibrary.pc 中,Libs 指向存储我的自定义 .dll 的位置,即 ../gwan/libraries/cs/dll/。这个位置不能更改,因为我相信 gwan 中有一些设置可以搜索这个特定目录。

第二期:未引用程序集 'netstandard'。

/root/gwan_linux64-bit/0.0.0.0:8080/#0.0.0.0
/csp/testdll.cs(12,24): error CS0012: The type `System.Object' is defined in an assembly that
is not referenced. Consider adding a reference to assembly `netstandard, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
Compilation failed: 1 error(s), 0 warnings

此问题是由于 mono 不支持 .NET Standard 2.0 而我的库是使用此框架构建的。为了解决这个问题,我构建了另一个针对 .NET Framework 4.6.1 的库。

因此,对于 G-WAN's FAQ 中 C# 部分后面的那些人,您需要在目录 /usr/lib64/pkgconfig 中为您的库创建一个包文件 (.pc),如上所述。