使用 Python.Net 导入具有依赖项的 .NET Standard 2.0 class 库

Importing .NET Standard 2.0 class library with dependencies using Python.Net

我有一个 .NET Standard 2.0 class 库,我正尝试使用 Python。 该库依赖于一些私有和 public NuGet 包。

我设法从 artifact on appveyor 安装了 pythonnet 的最新开发版本,我可以 运行 以下导入代码:

import clr
import sys
sys.path.append(r'C:\....\My.Library\bin\Debug\netstandard2.0')
ref = clr.AddReference("My.Library")

上面的代码 运行 很好,但是当我尝试从我的模块名称空间导入时...

from My.Library import MyClass
# >>> ModuleNotFoundError: No module named 'My'

当我尝试做 ref.get_ExportedTypes() 时,我得到这个:

System.IO.FileNotFoundException:
 Die Datei oder Assembly "Google.Protobuf, Version=3.6.0.0, Culture=neutral, PublicKeyToken=a7d26565bac4d604"
 oder eine Abhängigkeit davon wurde nicht gefunden.
 Das System kann die angegebene Datei nicht finden.
 bei System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes)
 bei System.Reflection.RuntimeAssembly.GetExportedTypes()

本质上这是一个关于 NuGet 依赖的 FileNotFoundException。 构建我的 DLL 文件/使用 NuGet 依赖项导入它的正确方法是什么?

谢谢

通过将所有依赖项放在一个目录中,导入即可。

中介绍了实现此目的的几个选项,例如 dotnet publish