代码之家  ›  专栏  ›  技术社区  ›  michaelosthege

使用python.net导入带有依赖项的.NET Standard 2.0类库

  •  2
  • michaelosthege  · 技术社区  · 8 年前

    我有一个.NET标准2.0类库,我正试图从Python中使用它。 该库依赖于一些私有和公共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依赖项导入它的正确方法是什么?

    谢谢

    1 回复  |  直到 8 年前
    推荐文章