Missing xaml.xr of a class library file in UWP

て烟熏妆下的殇ゞ 提交于 2019-12-04 03:41:45

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/34847919/missing-xaml-xr-of-a-class-library-file-in-uwp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!