Update your nuspec file to include .xr.xml files in your NuGet package

If you’re developing a library for Windows 8.1 or Windows Phone 8.1 XAML and are publishing it through NuGet, this article is for you.

After updating to Visual Studio 2013 Update 2, you’ll notice there’s a .xr.xml file in your build output for projects containing UI elements in XAML files. If the project doesn’t contain XAML files, no .xr.xml file is generated so an assembly filled with business logic is spared from this extra file. If you’re explicitly telling which files should be packaged through a .nuspec file like I do, this file will most likely be left out. Consuming this package will result in an error telling the .xr.xml file is missing.

Payload file '**\packages\*yourpackage*\lib\netcore451\YourAssembly\YourAssembly.xr.xml' does not exist.

As you can notice, the .xr.xml file has to be in a subfolder with your assembly name, similar to the compiled .xbf files (and XAML files used to be). Normally the .xr.xml file should be right next to your project output dll, but to be sure I’ve added subdirs to my nuspec file as well.

<files>
  <file src="$projectdir$\bin\$configuration$\$assembly$.*" target="lib\netcore451" />
  <file src="$projectdir$\bin\$configuration$\**\*.xbf" target="lib\netcore451\$assembly$" />
  <file src="$projectdir$\bin\$configuration$\**\*.xr.xml" target="lib\netcore451\$assembly$" />
</files>

What are these files?

I haven’t found any information about these files on MSDN yet, but according to Tim Heuer these are used “for store upload for compiling in the cloud”. When I hear this, I think about a lot of awesome scenarios possible in the future. We’ll see what time will bring.

If you have a peek into the file, it gives an overview of all used UI-related types, properties and methods in your assembly/app. Plenty of opportunities there as well I’d say.

<?xml version="1.0" encoding="utf-8"?>
<Roots >
  <Roots.PropertyPathNames>
    <RootPropertyPathName Name="DefaultViewModel" />
    <RootPropertyPathName Name="Items" />
    <RootPropertyPathName Name="Groups" />
    <RootPropertyPathName Name="NavigationHelper" />
    <RootPropertyPathName Name="GoBackCommand" />
    <RootPropertyPathName Name="Subtitle" />
    <RootPropertyPathName Name="Title" />
    <RootPropertyPathName Name="ImagePath" />
    <RootPropertyPathName Name="Group" />
    <RootPropertyPathName Name="Description" />
    <RootPropertyPathName Name="Item" />
  </Roots.PropertyPathNames>
  <Roots.RootTypes>
    <RootType FullName="Windows.UI.Xaml.Application">
      <RootProperty Name="Resources" />
    </RootType>
    <RootType FullName="System.String" />
    <RootType FullName="Windows.UI.Xaml.Controls.Page">
      <RootProperty Name="DataContext" />
      <RootProperty Name="Resources" />
      <RootProperty Name="BottomAppBar" />
      <RootProperty Name="Content" />
    </RootType>
    <RootType FullName="Windows.UI.Xaml.Data.Binding">
      <RootProperty Name="RelativeSource" />
      <RootProperty Name="ElementName" />
      <RootProperty Name="Source" />
    </RootType>
    <RootType FullName="Windows.UI.Xaml.Data.RelativeSource" />
    <RootType FullName="Windows.UI.Xaml.Controls.Grid">
      <RootProperty Name="Background" />
      <RootProperty Name="ChildrenTransitions" />
      <RootProperty Name="RowDefinitions" />
      <RootProperty Name="Children" />
      <RootProperty Name="ColumnDefinitions" />
      <RootProperty Name="Width" />
      <RootProperty Name="Height" />
      <RootProperty Name="HorizontalAlignment" />
      <RootProperty Name="Margin" />
      <RootProperty Name="DataContext" />
      <RootEvent Name="Tapped" />
      <RootMethod Name="GetRowSpan" />
      <RootMethod Name="SetRowSpan" />
      <RootMethod Name="GetColumn" />
      <RootMethod Name="SetColumn" />
      <RootMethod Name="GetRow" />
      <RootMethod Name="SetRow" />
    </RootType>
    ...
  </Roots.RootTypes>
</Roots>
Licensed under CC BY-NC-SA 4.0; code samples licensed under MIT.
comments powered by Disqus
Built with Hugo - Based on Theme Stack designed by Jimmy