Forum Visual Studio


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

How is the "Content" build action treated by Xamarin.Forms?

Hello all,

I'm working with a Nuget package that, when installed, adds some binary files to the shared project with the build action "Content." In a Windows application, one could access these files' contents from within the application using Application.GetContentStream(Uri). (I'd link to the Microsoft documentation here, but I can't yet post links on the forums.) This functionality, however, isn't part of the .NET standard and isn't accessible on mobile platforms.

While digging through some of the generated build files, however, I noticed that under MyProject/MyProject.Android/obj/Debug/90/assets, these content files had been copied. This surprised me, as I had never manually copied the files into MyProject.Android/Assets. Furthermore, in MyProject/MyProject.Android/obj/project.assets.json, the files were listed under their respective nuget package.

Having observed this behavior, I have two questions:
1. What happens to files with a Build Action of "Content?" (Particularly on iOS, since I was only able to find these files on Android.) Are there any documentation articles that describe what's happening here?
2. Is there any cross-platform way to access files with a Build Action of "Content?"
2a (bonus question). If not, what's the most elegant way to access static resources (like binary files) across platforms? (I've used platform-specific implementations like AndroidAssets in the past, but a cross-platform solution would be ideal.)

Thank you!

Best Answer


Sign In or Register to comment.