UWP 中缺少类库文件的 xaml.xr [英] Missing xaml.xr of a class library file in UWP

查看:35
本文介绍了UWP 中缺少类库文件的 xaml.xr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在 UWP 项目中使用的类库项目.如果我在类库中添加任何 usercontrol xaml 文件并构建它,它构建得很好.但是UWP项目报错找不到.xr文件.

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.

我是否需要将任何文件夹中的 .xr 文件从外部添加到我的 UWP 项目中?

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

推荐答案

是的,对于一个包含 XAML 文件的类库,如果我们想引用其他项目中的 dll,我们不仅需要 dll 本身,还需要 .xr.xaml 文件和其他一些文件.因为在 UWP 环境中,资源不再嵌入到程序集中,而是作为内容放置在 dll 旁边.查看类似案例:如何将xbf文件添加到visual studio项目.

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(类库名称)文件夹
    • ClassLibrary1.xr.xml
    • UserControl.xaml(用户控件 XAML 文件)

    要获取这些文件,我们可以检查生成库布局"项目属性页面下的构建配置中的选项.

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

    然后我们可以将这些文件复制到任何地方,UWP项目只需要在Visual Studio中添加对ClassLibrary1.dll文件的引用,Visual Studio在构建时会自动拾取这些文件并将它们放入appx包中应用.

    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.

    这篇关于UWP 中缺少类库文件的 xaml.xr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆