Forum Cross Platform with Xamarin


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.

Is there a cross platform way to include string resources from class library projects?

StuartLodgeStuartLodge USBeta ✭✭✭
edited October 2012 in Cross Platform with Xamarin

I'm currently trying to include some JSON files in a shared class library project.

I'd hoped to use Resources for this - but the portable resources only seem to support inline strings and images - not resource text files.

Is there any way to include resource text files within a library project (portable or not) and to then be able to access them at runtime?

I know I can embed the files as Content in each of the clients, but I'm trying to avoid cut-and-paste or shortcut-and-link if there is a way. It would be lovely if all the client apps have to do is to reference the library - not reference the library and copy in some resource files too.




  • JonathanPeppersJonathanPeppers USInsider, Beta, University ✭✭
    edited October 2012

    Have you tried just adding these files to the project and using build action "EmbeddedResource"?

    To get them out you can do something like:

    var streamToJson = Assembly.GetExecutingAssembly().GetManifestResourceStream("YourNamespace.YourFile.json");

    You could put this in a class library, and supply a helper method that calls this.

  • StuartLodgeStuartLodge USBeta ✭✭✭

    Thanks Jonp
    That looks like it might be perfect - will give it a spin

  • StuartLodgeStuartLodge USBeta ✭✭✭

    I've still not tried this workaround... but someone else has and it works :) Thanks again JonP :)

  • AndyDentrealmAndyDentrealm USMember
    edited January 2016

    Tip if you are using say a shared project with two platform specific projects, the filename will be generated using the Default Namespace in the Settings - General - Main Settings.

    So, if you want to use a fixed string for shared code to open the resource, eg: `"MyNamespace.Blah.csv" then you have to go into each target's settings and change Default Namespace from "MyNamespace.IOS" to just "MyNamespace" and similarly "MyNamespace.Droid" to just "MyNamespace"

Sign In or Register to comment.