NuGet:未添加对运行时文件夹中程序集的引用

编程入门 行业动态 更新时间:2024-10-28 03:17:52
本文介绍了NuGet:未添加对运行时文件夹中程序集的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个针对两种不同操作系统/框架的项目:

I have a project that targets two different operating systems/frameworks:

  • net461 在 Windows 和
  • netcoreapp2.0 在 OSX 上
  • net461 on Windows and
  • netcoreapp2.0 on OSX
  • 我正在尝试弄清楚如何为 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:未添加对运行时文件夹中程序集的引用

    本文发布于:2023-11-13 09:15:14,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1583979.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:文件   程序   夹中   NuGet

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!