0

I am trying to make a multiplatform package for Python.NET, targeting .NET Standard 2.0, using this project.

I managed to create a NuGet package with the following structure:

ref
|- netstandard2.0
 |- Python.Runtime.dll
runtimes
|- win
 |- lib
  |- netstandard2.0
   |- Python.Runtime.dll
|- linux-x64
 |- ...

This package works perfectly with a test app, based on the new .csproj format + PackageReferece, but only if I target netcoreappX.X. In that case it copies the whole runtimes folder to the output on dotnet publish and runs without a problem.

If I change TargetFramework to net472, both dotnet build and dotnet publish on Windows fail to copy any version of Python.Runtime.dll from the package, causing FileNotFoundException: Could not load file or assembly 'Python.Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

The same exception is raised when trying to run from Visual Studio.

The exception actually makes sense, as I can see the assembly is not copied to the output directory.

Now the question is which of the following is the problem, and how do I fix it:

  1. my .nuget package lacking something, so nothing is picked up for net472 target (though I'd expect it simply using netstandard2.0 stuff)
  2. my test app .csproj is missing something (maybe I need to specify in the .csproj all the supported runtimes?)
  3. a setup like this is not supported by tooling at all

If there is a solution to the above problem, would it also work for the old-style .NET Framework projects with packages.config?

LOST
  • 2,956
  • 3
  • 25
  • 40

1 Answers1

0

As suggested by Oren Novotny in https://github.com/dotnet/cli/issues/10806, there are two important things.

When using dotnet run or dotnet publish with net4xx targets, in this case --runtime has to be specified.

For dotnet publish a generic one seems to be fine: dotnet run -r win.

For dotnet run I had to specify a concrete one: dotnet run -r win7-x64.

To avoid that, I'd have to add lib/net4XX/ to the package in addition to its current content (not tried yet).

LOST
  • 2,956
  • 3
  • 25
  • 40