将C#dll与G-WAN一起使用

问题描述 投票:0回答:2

我的目标是应用在G-WAN上运行并连接到Azure存储的创建脚本。所以为了实现这一点,我首先尝试如何将dll链接到G-WAN中的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

但上述错误仍未解决。

我目前的设置如下

  • CentOS7.1804
  • G-WAN 7.12.6 64位(2016年2月8日16:33:28)
  • Mono JIT编译器版本3.0.2(tarball Wed Sep 5 03:46:28 EDT 2018)

下面是类库,使用.NET Standard 2.0使用System;

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);
    }
}

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

c# dll centos mono g-wan
2个回答
0
投票

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

我想,在某些人的心目中,这是“不可阻挡的进步之旅”。

John(上图)可能提出的建议是将您的G-WAN C#库的功能嵌入到C#脚本中(或作为G-WAN / libraries文件夹中的源代码) - 除非您有任何问题(速度,内存)库是巨大的,并被数百个脚本使用。

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


0
投票

第一期:缺少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),如上所述。

© www.soinside.com 2019 - 2024. All rights reserved.