Xamarin Folder Structure Explained

Now that we’ve created our project called Note Taker, you’ll notice there are 4 folders. The first one just called NoteTaker is our shared project. Now this folder is where we’re going to store all of our shared code. So, all of the code for example, in this file if I double click it, it will open it is accessible using both NoteTaker.droid for Android and NoteTaker.iOS for iPhone and iPad. If you put code for example in NoteTaker.droid NoteTaker.iOS won’t be able to access it, and there’s a very good reason for that it’s because iOS and Android are very different code-wise. So, you never want to share your iOS with your Droid code, ever, ever, ever! Sometimes within the shared project we can have what they called a conditional compiler, which looks something like this. If, Android and we can write endif and #endif, and this basically says, anything I write here will be applied to anything I want to build for iOS, and anything I write here will be applied to anything I want to write for Android. If I want to write for Android, it will of course ignore everything in the iOS section, but we will come to that much later on. That’s just a quick note. Ok, going to close that. So, if we come down on our folders here, we have NoteTaker.droid and NoteTaker.iOS. Now, the iOS one is in bold. That means it’s the currently active one. So when we click play up here it’s going to send it to our iPhone, or to our simulator, or our iOS device, to whatever we’ve chosen. If we want to change which project we have active, you go to droid, you right+click, and you go to set as start up project. So if I click that now, it now comes up at the top with the bunch of Android devices. Now, sometimes you would be in let’s say release and then you right+click a project, and you won’t have set a start up project. It’s a common error that happens and I don’t know why Xamarin does it, but just know it’s best to click debug iPhone simulator, right click and then it appears again. Ok, so make sure that you’ve selected iOS as your start up project. Close your Droid one, because we don’t want to look at that in the moment. So, in your iOS project we have a bunch of folders once again, and these base folders that your project starts with you should never ever move or change the name of. You can add folders to here if you right click it and you click add new folder, that’s absolutely fine. However, these four here you should never delete. Otherwise, your app will not build and you’ll have lots of errors. So, I mentioned it earlier but it should go without saying, any code we write for Apple goes into here: NoteTaker.iOS. Any code you write for Android goes in here: NoteTaker.Droid, and we never want to mix the code between the two. Shared code goes into just NoteTaker and that code in NoteTaker will be accessible by both Android and iOS. Now that we’ve covered where we put our code, and the whole project structure, join me in the next lesson when we walk through the Xamarin Studio graphical user interface.

One thought on “Xamarin Folder Structure Explained

  • July 6, 2017 at 8:20 am

    This information is priceless. Where can I find out more?|


Leave a Reply

Your email address will not be published. Required fields are marked *