如何在 NuGet 包中正确包含 rd.xml 文件? [英] How to properly include an rd.xml file in a NuGet package?

查看:29
本文介绍了如何在 NuGet 包中正确包含 rd.xml 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个大量使用反射的库,并且面向 .NET Core (netstandard1.3) 和完整的 .NET (net451).

I'm developing a library that makes heavy use of reflection, and targets both .NET Core (netstandard1.3) and full .NET (net451).

要使其与 .NET Native(即 UWP Release 版本)一起使用,它需要一个 rd.xml 文件,如下所示:

To make it work with .NET Native (i.e. UWP Release builds), it needs an rd.xml file, which looks like this:

<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
  <Library Name="MyLibrary">
    <!-- bunch of directives here -->
  </Library>
</Directives>

我知道这些指令有效,因为使用该库将它们插入到 UWP 应用程序的 Application.rd.xml 文件中可以正常工作,但应用程序会因为缺少元数据而崩溃.

I know these directives work because inserting them into the Application.rd.xml file of an UWP app using the library works fine, but the app crashes because of missing metadata otherwise.

使用这篇博文,我尝试通过将 uap10.0 添加到支持的框架来使我的库兼容,使用与 netstandard1.3 + System.Runtime<相同的依赖项/code>,然后将以下内容添加到我的 project.jsonpackOptions 中:

Using this blog post, I tried making my library compatible by adding uap10.0 to the supported frameworks, using the same dependencies as netstandard1.3 + System.Runtime, then adding the following to my project.json's packOptions:

"files": {
  "include": "Properties/MyLibrary.rd.xml",

  "mappings": {
    "lib/uap10.0/MyLibrary/Properties/MyLibrary.rd.xml": "Properties/MyLibrary.rd.xml"
  }
}

dotnet pack -c Release 生成的包确实在预期位置包含 MyLibrary.rd.xml 文件.

The package produced by dotnet pack -c Release does indeed contain the MyLibrary.rd.xml file in the expected place.

但是,当我在 UWP 应用程序中使用该包(来自 NuGet,而不是作为项目参考)时,.NET Native 不会获取 .rd.xml 文件;应用因缺少元数据错误而崩溃.

However, .NET Native doesn't pick up the .rd.xml file when I use that package (from NuGet, not as a project reference) in an UWP app; the app crashes with missing metadata errors.

我错过了什么?

推荐答案

Matt Whilden 的评论让我走上了正确的道路;基于 .xproj 的项目没有文件属性,但 Embedded Resource 的正确等效项是框架部分中的 buildOptions/embed,而不是 packOptions/files:

Matt Whilden's comment got me on the right path; .xproj-based projects do not have file properties, but the correct equivalent of Embedded Resource is buildOptions/embed in the framework section, not packOptions/files:

"uap10.0": {
  "buildOptions": {
    "embed": {
      "include": "Properties/MyLibrary.rd.xml"
    }
  }
}

这篇关于如何在 NuGet 包中正确包含 rd.xml 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆