如何从 UWP 的 Net Standard 2.0 类库访问内容

编程入门 行业动态 更新时间:2024-10-26 06:29:58
本文介绍了如何从 UWP 的 Net Standard 2.0 类库访问内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我们有一个 UWP 应用,它引用了一个 UWP 类库.UWP 类库有一个 Common 文件夹,其中包含运行时所需的文件.

We have a UWP app which references a UWP class library. The UWP class library has a Common folder with files that are required at runtime.

文件被标记为复制为内容".文件被复制到 ..UWPinx64DebugAppxCommon.应用程序在运行时在 package.InstalledLocationCommon

The files are marked Copy As Content. The files are copied to ..UWPinx64DebugAppx<LibraryName>Common. The app finds those files at runtime in package.InstalledLocation<LibraryName>Common

UWP 类库现在是 .NET Standard 2.0 类库.在运行时,Common 文件夹现在被复制到与 Appx 文件夹 ..UWPinx64DebugCommon 相同级别的文件夹中,我无法访问.我试过了

The UWP class library is now a .NET Standard 2.0 class library. At runtime the Common folder is now copied to a folder at the same level as the Appx folder ..UWPinx64DebugCommon where I cannot access. I tried

StorageFolder installedFolder = package.InstalledLocation; StorageFolder parentFolder = await installedFolder.GetParentAsync();

但 parentFolder 返回 null.如何访问作为 .NET Standard 2.0 类库内容的文件和文件夹?

but parentFolder returns null. How do I access files and folders that are content from a .NET Standard 2.0 class library?

推荐答案

您无法从 InstalledLocation 获取 .Net 标准类库中的文件.要访问文件,您可以将文件标记为Embedded Resource 和Copy Always,然后公开访问文件流的方法.

You can not get the file in the .Net standard class library from the InstalledLocation. To access the files, you can mark the file as Embedded Resource and Copy Always, then expose a method to access the file stream.

这是一个非常相似的线程,你可以看到实现它的详细步骤,

Here is a very similar thread, you can see the detailed steps to achieve it,

如何在 ARM 平台的 .NET Standard 1.4 库中包含资产文件?

更多推荐

如何从 UWP 的 Net Standard 2.0 类库访问内容

本文发布于:2023-11-14 09:03:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1586791.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:类库   内容   Net   UWP   Standard

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!