我有一个试图从 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/