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

标签 python .net dll nuget python.net

我有一个试图从 Python 中使用的 .NET Standard 2.0 类库。
该库依赖于一些私有(private)和公共(public) NuGet 包。

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

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 , 显示在 How to get .NET Core projects to copy NuGet references to build output?

关于python - 使用 Python.Net 导入具有依赖项的 .NET Standard 2.0 类库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51609699/

相关文章:

python - 索引错误: list assignment index out of range in Python

python - 是否提供包含英文单词(包括频率)的列表?

python - 使用python从docker容器访问主机os文件

c# - 为类库使用系统命名空间 : good or bad

.net - 无法在VS2010中调试.NET框架代码

python - 如果值包含字符串,则设置另一个列值

c# - 数据绑定(bind) : 'System.Web.UI.Pair' does not contain a property with the name 'First'

python - 如何将数组传递给使用 python 用 c 编写的共享库 (.dll)

c# - 将配置文件的内容读入与之关联的 dll

c++ - DLL 函数从参数获取错误值