我正在尝试使用this project为Python.NET制作一个多平台包,目标是.NET Standard 2.0。
我设法创建了一个具有以下结构的NuGet包:
ref
|- netstandard2.0
|- Python.Runtime.dll
runtimes
|- win
|- lib
|- netstandard2.0
|- Python.Runtime.dll
|- linux-x64
|- ...
这个包与测试应用程序完美配合,基于新的.csproj格式+ PackageReferece
,但只有我定位netcoreappX.X
。在这种情况下,它将整个runtimes
文件夹复制到dotnet publish
上的输出并运行没有问题。
如果我将TargetFramework
更改为net472
,Windows上的dotnet build
和dotnet publish
都无法从包中复制任何版本的Python.Runtime.dll,从而导致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.
尝试从Visual Studio运行时引发相同的异常。
该异常实际上是有道理的,因为我可以看到程序集未被复制到输出目录。
现在问题是以下哪个是问题,我该如何解决它:
net472
目标找到任何东西(虽然我希望它只是使用netstandard2.0
的东西)如果有上述问题的解决方案,它是否也适用于使用packages.config
的旧式.NET Framework项目?
正如Oren Novotny在https://github.com/dotnet/cli/issues/10806所建议的,有两个重要的事情。
当使用dotnet run
或dotnet publish
与net4xx
目标时,在这种情况下必须指定--runtime
。
对于dotnet publish
来说,通用的似乎很好:dotnet run -r win
。
对于dotnet run
,我必须指定一个具体的:dotnet run -r win7-x64
。
为了避免这种情况,除了当前内容(尚未尝试)之外,我还必须将lib / net4XX /添加到包中。