4

I have a .NET Standard 2.0 class library that I'm trying to use from Python. The library has dependencies on some private and public NuGet packages.

I managed to install a recent dev version of pythonnet from the artifact on appveyor and I can run the following import code:

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

The code above runs fine, but when I try to import from my modules namespace...

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

When I try to do ref.get_ExportedTypes(), I get this:

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()

Essentially this is a FileNotFoundException about the NuGet dependency. What is the right way to structure my DLL files / to import it with NuGet dependencies?

thanks

4
  • 1
    I have the same problem and just opened an issue in github: github.com/pythonnet/pythonnet/issues/711 Commented Aug 4, 2018 at 19:37
  • why can't you just download/extract all your dependencies from nuget? are you trying to match Visual Studio experience with C#?! Commented Aug 7, 2018 at 18:12
  • I have developed the .NET Standard class library and would like to create a distributable python package that exposes the API of my library to Python users. WIll it be sufficient to put the DLLs of my library and all the NuGet dependencies into the same directory and do sys.path.append(r'./allthedlls') ? Some magic helper function that analyzes a DLLs dependencies and automatically downloads & extracts them from NuGet would be awesome though. Commented Aug 11, 2018 at 16:12
  • moving to github.com/pythonnet/pythonnet/issues/711 because formatting in Stackoverflow comments is awful. Commented Aug 13, 2018 at 7:21

1 Answer 1

3

By putting all dependencies into one directory, the import can work. Several options how to achieve this, such as dotnet publish, are presented in How to get .NET Core projects to copy NuGet references to build output?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.