【问题标题】:How to properly package and consume .NET Standard library with multiple runtimes on net472?如何在 net472 上正确打包和使用具有多个运行时的 .NET Standard 库?
【发布时间】:2019-02-12 06:43:10
【问题描述】:

我正在尝试使用 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】:

    正如 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/ 添加到包中,以及当前的内容(尚未尝试)。

    【讨论】:

      猜你喜欢
      • 2018-06-23
      • 2020-01-29
      • 1970-01-01
      • 2018-07-06
      • 2020-05-10
      • 1970-01-01
      • 1970-01-01
      • 2017-07-29
      • 1970-01-01
      相关资源
      最近更新 更多