Forum Xamarin.iOS


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.

Force adding of Resource files to the bundle in X Studio?

How do I do this?

I've noticed that if I include .png files in the project files, these get inserted into the bundle automatically, which is great. However, I have a ton of non standard files, with made up extensions, that I need to go into the bundle as resources, and they are just being put there. I can't find anything in X Studio that shows me the bundle copy step (like there is in XCode), so I can force them to be included - how do I do this?

I've been looking though all the solution and project options, and I suspect it's there but I've just not seen it.



  • JohnMillerJohnMiller USForum Administrator, Xamarin Team Xamurai
    edited March 2013

    Hey Jake,

    Are you referring to the build action of the files?

    If you right click on a file in the Solution Explorer in Xamarin Studio, you get the below options under the Build Action menu (attached image)

    Maybe you want to select the BundleResource options for your custom files, if not Consider this area of the documentation for an idea of which Build Action to choose:

  • JakeSimpsonJakeSimpson USMember

    Yeah, I found it in the end.

    The issue was that all my assets are under directories. I was trying to add a directory as a build event, and the option just wasn't showing up when select a directory. It only shows up when you select a specific file.

    I had to spend an hour going through each directory (and there were hundreds) mass selecting each file underneath it to add them as content.

    Can I suggest that we are able to add this feature directly to selection of a directory, and not just individual files? And further, have it so when this option is selected, if any new files / directories get added under the one where the option is selected, everything new just automatically gets added as a bundle resource.

    Incidentally, what's the difference between a BundleResource and Content? Both appear to put files into the bundle?


  • JeffreyStedfastJeffreyStedfast USXamarin Team Xamurai
    edited March 2013

    All files that are added to the project's "Resources" dir automatically get assigned the Build Action of "BundleResource"

    You can also select multiple files at once, right click, and then select Build Action -> BundleResource.

    Content is obsolete, don't use it :-)

    It's been super ceded by BundleResource, which allows you to set a LogicalName attribute (if you select a file and right-click and select "Properties"), the logical name allows you to specify an alternative relative path/file name than the name it exists as in your project.

    For example, you could have a file named "MyAppIcon.icns" but override the LogicalName to be "Icon.icns" and it will be copied to your app bundle with the name "Icon.icns" instead of "MyAppIcon.icns".

  • JakeSimpsonJakeSimpson USMember

    You cannot ADD a Resources Directory in Xamarin Studio. It tells you that this directory name is a reserved name and you have to rename it. I can't work out how to add the damn thing in the first place.

    I discovered adding multiple files, but that doesn't really help when the project you are porting has tens of thousands of asset files in hundreds of directories. If I could select the top level directory and just say "Add everything below this as a Build Resource", then I wouldn't have to spend hours going through each directory by hand adding them each, one at a time.

  • JakeSimpsonJakeSimpson USMember

    While we are talking about it - I can crash out a few of the features of Xamarin Studio 100% of the time, giving me a nice Exception caught stack dump. Is there a public front end to add bug reports on this product? I'd love to be able to submit these to the dev team, and I'm pretty sure they'd want to see them...

  • JeffreyStedfastJeffreyStedfast USXamarin Team Xamurai

    Xamarin.Mac and iOS projects default to creating a Resources folder when you create a new project.

    At least recent versions do (since one of the 3.0.x releases)

  • JakeSimpsonJakeSimpson USMember

    And if you delete it, because other projects that are part of the solution already have a resource folder in them, then you CANNOT re-add it.

  • JeffreyStedfastJeffreyStedfast USXamarin Team Xamurai
    edited March 2013

    I just tested this by creating a new Xamarin.iOS project and deleting the Resources folder. Then I did File -> Add New Folder and added a Resources folder and it worked fine.

    What error are you getting?

  • JakeSimpsonJakeSimpson USMember

    OK. I have a solution with 5 projects in it. I go to the start up project, select it and do Add Folder. It create a folder and I get to name it. I call it Resources. I immediately get an error telling me "File or Directory name is already in use. Please choose a different one."

    In that project, there is NO Resource directory. There might be in one of the other projects, it's hard to tell. They are all 3rd party lib projects and as such, I can't really modify them very much.

  • JeffreyStedfastJeffreyStedfast USXamarin Team Xamurai

    Okay, I think I know what is happening.

    When you removed the "Resources" folder, you only removed it from the project, you didn't delete it from the File System. When you add a new folder and try to rename it to "Resources", since there is already a "Resources" folder on the File System, it won't let you rename it.

    What you should do in this case is right-click on the project and then select "Add Existing Folder..."

  • JakeSimpsonJakeSimpson USMember

    Urrrgghhh! :) I should have realised that! Looking in the project, yes, I see it, and I also see other temp dirs I was creating. My mistake, I thought I was creating virtual directories, like you do in XCode.

    Trouble is, the resources I need to use are located elsewhere in the code tree. I cannot add the resources under that specific directory, since they are located elsewhere, for practical content generation reasons. I don't own this code base, so I can't just be moving them around, unfortunately. I need to be referencing the assets from a different directory.

    Now, I had thought that I could just "move" the directory reference to my actual assets to under the resource directory, however nothing happens when I do that. Nothing moves and there is no error message. I'm presuming that because these aren't virtual directory references, but are referring to actual directories, this won't work?

    Any thoughts on what I can do about this?

  • JeffreyStedfastJeffreyStedfast USXamarin Team Xamurai

    You can link to files anywhere on the file system.

    When you right-click the Resources folder and select "Add Files", you should be able to select files from anywhere... once you click OK, I'm pretty sure Xamarin Studio will ask you if you want to "Move Files", "Copy Files", or "Create a Link" (not 100% sure on the wording, but that should be close).

    If you select "Create a Link", Xamarin Studio won't actually copy the physical files into the directory, what it'll do is reference those files in the .csproj file as links, which will behave the same as any physical file, just that it'll actually live somewhere else on the system.

    Does that work for what you need?

  • JakeSimpsonJakeSimpson USMember

    This does work, however the statement that "any files put under the resources directory automatically become BundleResources" is false, at least in my experience.

    What I've got is a content directory that is not physically under the resources directory, but is a reference under the Resource directory in the Xamarin Studio project. I just added about 10,000 files - all of them non standard extensions (ie not .wav or .png or whatever) and not one of them has been added as a BundleResource - all of them have a build action of None.

    I suspect this is because this is a referenced directory, not a physical one that is present under the resources directory. Either way, all that work to get it into the Resources directory was, unfortunately, a little pointless. Now I have to go through and set every file individually (like I did last time), since there is no option to do this at a directory level, only at the individual file level (and there are hundreds of directories that the content is inside of, so it's opening each and every directory, selecting all the files, setting their build action, and onto the next dir.)

  • i had install the xamarin software
    but i got one problem ..........when i am doing app creation.....that should be with layout......
    while i press the layout it shows error message
    System.Net.Sockets.SocketException (0x80004005): An attempt was made to access a socket in a way forbidden by its access permissions
    at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
    at System.Net.Sockets.Socket.Bind(EndPoint localEP)
    at System.Net.Sockets.TcpListener.Start(Int32 backlog)
    at System.Net.Sockets.TcpListener.Start()
    at Xamarin.AndroidDesigner.JavaProcessConnection.DoConnect(CancellationToken token)
    this was the message its showing...
    can you please find out problem...
    &send the solution to that one..................:)

  • OnurHazarOnurHazar USUniversity ✭✭✭

    @JeffreyStedfast I set my iOS project resources build action to "BundleResources" but I couldn't find any info about quick properties -> copy to output directory setting. Is it also necessary to check?

  • JeffreyStedfastJeffreyStedfast USXamarin Team Xamurai

    No, never use "Copy to Output Directory".

  • AgustinLeyvaAgustinLeyva USMember
    edited November 2016

    Hi, im not shure if my question its in correct place.
    It's my first posto in Xamarins Forums.
    Im learning to develop iOS app.
    the intention of the app is:
    Download .png files from directory web (1rst question is how to save on the device, not temporal).
    How to read this downloaded images to show in other view controller
    Thanks in advance
    Im developing with Xamarin VisualStudio 2015 (Proffesional Edition)

  • DaveHuntDaveHunt USMember ✭✭✭✭✭

    @AgustinLeyva said:
    Hi, im not shure if my question its in correct place.

    You're in the right forum, just not the right topic. Your question doesn't have anything to do with the topic of this thread. You should create a new thread and ask your question there.

Sign In or Register to comment.