How to include asset files in a .NET Standard 1.4 library in ARM platform?

一世执手 提交于 2019-12-24 19:28:39

问题


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

thanks


回答1:


If you want to get assets files from a .NET Standard library, you would need to mark the file as EmbeddedResource and Copy Always.

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;
        }
    }
}

Please note this line assembly.GetManifestResourceStream("ClassLibrary1.Assets.dog.jpg");

The ClassLibrary1 is the namespace, the Assets is the Assets folder in the library project, the dog.jpg is the file.

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.



来源:https://stackoverflow.com/questions/47346712/how-to-include-asset-files-in-a-net-standard-1-4-library-in-arm-platform

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