c# - 如何使用 dotnet core 从 linux 共享库中导入公共 ref 类
问题描述
我看过其他一些关于这个的帖子,要么它们太简单,要么太旧。我宁愿不使用 Visual Studio,因为我对它不是很熟悉,也没有安装它。我在 ubuntu 中使用 dotnet core cli。我有一个共享库vendor.so
我正在尝试使用内部公共引用类中的方法vendor.so
这是代码
vendor.h
namespace Vendor_namespace{
public ref class Vendor
{
public:
int myMethod(...)
MyCSharp.cs
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Program {
class Program {
[DllImport("Vendor.so")]
static extern class Vendor;
public static void main(string[] args) {
Vendor foo = new Vendor();
foo.myMethod(...)
}
这是我在运行代码时遇到的错误
Program.cs(76,13): error CS0246: The type or namespace name 'Vendor' could not be found (are you missing a using directive or an assembly reference?) [/../../MyCSharp/MyCSharp.csproj]
Program.cs(76,36): error CS0246: The type or namespace name 'Vendor' could not be found (are you missing a using directive or an assembly reference?) [/../../MyCSharp/MyCSharp.csproj]
解决方案
推荐阅读
- excel - 谷歌表格的 Excel 中 VBA 的 Range.Value 等价物是什么?
- jquery - 在 Angular 中动态加载 html 控件
- reactjs - 如何使用 Gatsby 和 create-react-app 添加 react-native out-of-tree 平台?
- log4j2 - 我想在 log4j2.xml 中获取每日日期的单独日志,而不是日志被覆盖
- events - 是否可以使用 INET++ 在 OMNET++ 中的 WSN 环境中创建事件(温度、湿度、噪音)
- cordova - Ionic 3 cordova-plugin-advanced-http 主机不匹配问题
- java - 抛出错误时不显示 Vaadin 错误处理窗口
- oracle - pentahokettle如何根据之前输入的数据运行不同的sql获取数据
- python - Pandas read_csv usecols 和名称无法正常工作
- elixir - 使用 Elixir 插值映射键