如何在 ARM 平台的 .NET Standard 1.4 库中包含资产文件? [英] How to include asset files in a .NET Standard 1.4 library in ARM platform?
问题描述
如果平台是ARM,有谁知道引用资产的正确方法是什么?在 x86 中,我可以使用带有链接的 appX 文件夹,但它不能在 ARM 上运行
Anyone know what is the correct way of referencing assets if the platform is ARM? In x86 I can use appX folder with linking but its not working on ARM
谢谢
推荐答案
如果您想从 .NET Standard 库中获取资产文件,您需要将该文件标记为 EmbeddedResource
和 始终复制
.
If you want to get assets files from a .NET Standard library, you would need to mark the file as EmbeddedResource
and Copy Always
.
然后,您需要添加一个方法来在 .NET Standard 库的类中获取这些文件.例如:
Then, you need to add a method to get these files in your .NET Standard library's class. For example:
namespace ClassLibrary1
{
public class Class1
{
public static Stream GetImage()
{
var assembly = typeof(Class1).GetTypeInfo().Assembly;
Stream stream = assembly.GetManifestResourceStream("ClassLibrary1.Assets.dog.jpg");
return stream;
}
}
}
请注意这一行 assembly.GetManifestResourceStream("ClassLibrary1.Assets.dog.jpg");
ClassLibrary1
是命名空间,Assets
是库项目中的 Assets 文件夹,dog.jpg
是文件.
The ClassLibrary1
is the namespace, the Assets
is the Assets folder in the library project, the dog.jpg
is the file.
在我的示例中,我将图像文件放在 Assets 文件夹中,如果将其放在项目的根目录中,那么这一行应该是这样的:
In my sample, I put the image files in the Assets folder, if put it in root directory of project, then, this line should be like this:
assembly.GetManifestResourceStream("ClassLibrary1.dog.jpg");
您可以使用以下代码查看所有嵌入的资源:
You could use the following code to see all embedded resource:
foreach (var res in assembly.GetManifestResourceNames())
{
System.Diagnostics.Debug.WriteLine("found resource: " + res);
}
之后,在你的主项目中,你可以调用这个方法来获取这些文件.
After that, in your main project, you could call this method to get these files.
这篇关于如何在 ARM 平台的 .NET Standard 1.4 库中包含资产文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!