.net - 如何在 net472 上正确打包和使用具有多个运行时的 .NET Standard 库?
问题描述
我正在尝试使用这个项目为 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
,则Windowsdotnet build
和dotnet publish
Windows 都无法从包中复制任何版本的 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 运行时会引发相同的异常。
该异常实际上是有道理的,因为我可以看到程序集没有复制到输出目录。
现在的问题是以下哪个是问题,以及如何解决它:
- 我的 .nuget 包缺少某些东西,因此没有为目标拾取任何东西
net472
(尽管我希望它只是使用netstandard2.0
东西) - 我的测试应用程序 .csproj 缺少一些东西(也许我需要在 .csproj 中指定所有支持的运行时?)
- 工具根本不支持这样的设置
如果上述问题有解决方案,它是否也适用于旧式 .NET Framework 项目packages.config
?
解决方案
正如 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/ 添加到包中。
推荐阅读
- python - 解析特定字段值的 JSON 数据条目
- c++ - 在 C++ 中检查单调时钟的滴答声是否等待免费?
- mysql - Apache2 + wsgi + mysql 不工作,但从 Django 它工作
- r - 为什么调色板只对所有条应用一种颜色?
- scala - 为什么我的 Spark Scala 作业在使用 Jedis 客户端读取/写入 Redis 池时挂起
- php - PHP 将数组组合成多维并渲染成 HTML 表格
- javascript - js字符串插值在haml中失败:javascript过滤器
- java - VB 的 SendKeys 类有 java 替代品吗?
- git - Git 等效于'repo start --head XXXX'
- .htaccess - HTACCESS:向 RewriteEngine 添加 FOLDER 异常