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

查看:92
本文介绍了如何在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>

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

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 ,然后将以下内容添加到我的 project.json packOptions

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 确实包含 M yLibrary.rd.xml 文件放在期望的位置。

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

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

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天全站免登陆