我有一个针对两种不同操作系统/框架的项目:
I have a project that targets two different operating systems/frameworks:
我正在尝试弄清楚如何为 NuGet 正确打包它.根据这篇文章,我应该能够像这样打包它们这个:
I'm trying to figure out how to correctly package this for NuGet. According to this post I should be able to package them like this:
/runtimes/win/lib/net461/myassembly.dll /runtimes/osx/lib/netcoreapp2.0/myassembly.dll当我将 NuGet 包添加到另一个项目时,打包的程序集不会作为对目标项目的引用添加.
By when I add the NuGet package to another project, the packaged assemblies aren't added as references to the target project.
然后我在某处读到您还需要将参考库添加到 /ref 文件夹中,所以我尝试了这个:
Then I read somewhere that you also need to add reference libraries to the /ref folder so I tried this:
/runtimes/win/lib/net461/myassembly.dll /runtimes/osx/lib/netcoreapp2.0/myassembly.dll /ref/net461/myassembly.dll /ref/netcoreapp2.0/myassembly.dll在这种情况下,程序集被添加为对目标项目的引用,我可以构建它,但所需的程序集不会复制到输出文件夹.
In this case the assemblies get added as a reference to the target project and I can build it, but the required assemblies aren't copied to the output folder.
关于所有这些的文档非常模糊,我相当迷茫.
The documentation on all this is extremely vague and I'm fairly lost.
我错过了什么?
相关的 NuGet 问题:github/NuGet/Home/issues/7316
Associated NuGet Issue: github/NuGet/Home/issues/7316
更新:我整理了一个示例项目,展示了我正在努力实现的目标.特别是请参阅自述文件底部,标题为NuGet Packaging".
Update: I've put together a sample project that demonstrates what I'm trying to achieve. In particular see the bottom of the readme, titled "NuGet Packaging".
推荐答案这就是我最终想出/猜到的(因为我能说的是,其中一些没有官方文档)
This is what I've finally figured out/guessed (because as best I can tell there's no official documentation for some of this)
- 添加到/runtimes 文件夹的文件不会自动添加为对目标项目的引用.
- /ref 和/runtime 文件夹应相互结合使用,并且仅用于 .NET Core 目标..NET Framework 目标显然不支持这些文件夹.
- /ref 文件夹用于编译时引用,此处添加的任何内容都将添加为对目标项目的引用.
- /ref 文件夹中的程序集不需要实现 - 每个公共 API 都可以抛出未实现的异常.但在实践中,您通常只需复制其中一个实现程序集并将其声明为编译时 API.
- 我读过(但我没有测试过)/ref 文件夹中的程序集必须是任何 CPU"版本.如有必要,您可以使用 CorFlags 实用程序为此修补实现程序集.
- /runtimes 文件夹用于为/ref 文件夹中包含的任何引用提供实现程序集.这些程序集在运行时和部署期间使用.
- /runtimes 文件夹可以包含仅在运行时需要且客户端项目不需要看到的其他程序集.这些额外的程序集不会作为参考包含在目标项目中,但可用于运行/部署.
- 正如其他人所提到的,/runtimes 文件夹中的文件不会复制到构建的输出文件夹中.相反,配置文件放置在那里,告诉运行时如何从 NuGet 缓存中找到/runtimes 文件.
- 对于 .NET Framework 目标(即:net461),只需使用/lib 文件夹,因为除了 Windows 之外,.NET 没有其他运行时.
把这一切放在一起,我原来的例子应该是这样的:
Putting this all together, my original example, should have looked like this:
/lib/net461/myassembly.dll (net461/Windows Compile and Runtime) /runtimes/osx/lib/netcoreapp2.0/myassembly.dll (netcore/OSX Runtime) /runtimes/win/lib/netcoreapp2.0/myassembly.dll (netcore/Win Runtime) /ref/netcoreapp2.0/myassembly.dll (netcore/* Compile Time)更多推荐
NuGet:未添加对运行时文件夹中程序集的引用
发布评论