如何在net472上正确打包和使用具有多个运行时的.NET标准库?

问题描述 投票:0回答:1

我正在尝试使用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 builddotnet 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运行时引发相同的异常。

该异常实际上是有道理的,因为我可以看到程序集未被复制到输出目录。

现在问题是以下哪个是问题,我该如何解决它:

  1. 我的.nuget包缺少某些东西,所以没有为net472目标找到任何东西(虽然我希望它只是使用netstandard2.0的东西)
  2. 我的测试应用程序.csproj缺少一些东西(也许我需要在.csproj中指定所有支持的运行时?)
  3. 工具根本不支持这样的设置

如果有上述问题的解决方案,它是否也适用于使用packages.config的旧式.NET Framework项目?

.net .net-core nuget .net-standard-2.0 .net-4.7.2
1个回答
0
投票

正如Oren Novotny在https://github.com/dotnet/cli/issues/10806所建议的,有两个重要的事情。

当使用dotnet rundotnet publishnet4xx目标时,在这种情况下必须指定--runtime

对于dotnet publish来说,通用的似乎很好:dotnet run -r win

对于dotnet run,我必须指定一个具体的:dotnet run -r win7-x64

为了避免这种情况,除了当前内容(尚未尝试)之外,我还必须将lib / net4XX /添加到包中。

© www.soinside.com 2019 - 2024. All rights reserved.