问题
I'm developing a library that makes heavy use of reflection, and targets both .NET Core (netstandard1.3
) and full .NET (net451
).
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>
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.
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"
}
}
The package produced by dotnet pack -c Release
does indeed contain the MyLibrary.rd.xml
file in the expected place.
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.
What am I missing?
回答1:
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"
}
}
}
来源:https://stackoverflow.com/questions/39687011/how-to-properly-include-an-rd-xml-file-in-a-nuget-package