Missing xaml.xr of a class library file in UWP
Asked Answered
V

1

6

I have a class library project which I am using in a UWP project. If I add any usercontrol xaml file in the class library and build it it builds fine. But the UWP project gives an error that it cannot find the .xr file.

Do I need to add the .xr file externally in any folder to my UWP project?

Vaal answered 18/1, 2016 at 5:37 Comment(0)
J
10

Yeah, for a class library with XAML files, if we want to reference the dll in other project, we need not only the dll itself but also the .xr.xaml file and some other files. Because in UWP environment, the resources are no longer embedded in the assembly but are placed next to the dll as content. See the similar case: How to add xbf files to visual studio project.

The files we need to reference like following:

  • ClassLibrary1(Class Library name) Folder
    • ClassLibrary1.xr.xml
    • UserControl.xaml (UserControl XAML file)
  • ClassLibrary1.dll
  • ClassLibrary1.pri

To get these files, we can check the "Generate library layout" option in the Build configuration under the project's Properties page.

Then we can copy these files to anywhere and the UWP project just need to add reference to the ClassLibrary1.dll file in the Visual Studio, Visual Studio will automatically pick these files up and put them in the appx package when it builds the app.

Jamestown answered 18/1, 2016 at 8:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.