问题
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