Sharing Projectsexplore Programming



Explore GitLab Discover projects, groups and snippets. Share your projects with others.

  1. Ms Project Sharing
  2. Microsoft Project Sharing

Welcome back to part 2 of the ongoing saga of sharing code across platforms using Xamarin. 0002The last time we talked about the why and when to share code, today we’ll cover one of the ways of how to share code.

Unfortunately we won’t be sharing pizza today, but there are 3 ways to share code across projects:

  1. Linked files
  2. Shared Projects
  3. Portable Class Libraries

Linked files are going the way of the dodo and generally are not used any longer and are being replaced in favor of Shared Projects. 0002So let’s0002investigate how to share code using “Shared Projects”, and in the next post in this series we’ll investigate Portable Class Libraries, or PCLs.

What are Shared Projects?

  • Learn more, build faster, and share your projects using community resources like the Inductive Automation Forums, Ignition Exchange, and Inductive University. Chat & Get Inspired Visit the forums to see and discuss projects with other makers, ask questions, and more.
  • Allowing others to get stuff in and out: Share your site. Project Web App has a new SharePoint-integrated security model that makes it easy to give your colleagues the right level of access. Simply click on the “Share your site” tile, type in the names of users who should get access, pick the appropriate permission level, and you’re done!

Ms Project Sharing

A good place to start with is defining exactly what is meant by a0002Shared Project. 0002To quote Xamarin:

Shared Projects let you write common code that is referenced by a number of different application projects. The code is compiled as part of each referencing project and can include compiler directives to help incorporate platform-specific functionality into the shared code base.

In other words, Shared Projects are a project type which get compiled directly into the project referencing them, and you can even use platform specific APIs within them0002– which are identified0002by preprocessor directives. 0002That means you can use specific iOS, Android or Windows Phone APIs within a Shared Project and the preprocessor directive ignores anything not a part of the platform you’re compiling for. 0002Under the hood, Visual Studio and Xamarin Studio treat Shared Projects the same way they treat linked files.

Shared Projects were introduced in Visual Studio 2013 R2 and also in Xamarin Studio 5.

Pros And Cons of Shared Projects

Advantages

One really0002cool thing about Shared Projects0002is that they0002have full access to all of the assemblies of .NET framework, which set them apart from the limited access that PCLs have.

You can use platform specific code within a Shared Project. 0002So that whiz-bang feature that you developed for Android, but don’t really need for iOS, can be included within the Shared Project itself. 0002Or more practically, certain folders within the file system are accessed differently across the platforms – but the differences in accessing those folders can be accounted for within a Shared Project.

One final benefit is that because the Shared Project is compiled directly into the referencing application’s binary – if there is a project in your solution which does not reference the Shared Project, it is not included at all in it’s binary. 0002No unnecessary bloat.

Project
Disadvantages

While a Shared Project does have full access to the .NET framework, you cannot add any references to the Shared Project itself. 0002That means any 3rd party libraries, even libraries that you’ve created elsewhere, are not available.

Another is no separate DLL is created – all of the Shared Project’s code is compiled to be a part of the referencing application’s binary itself. 0002Any assets, such as images or other media are compiled into the referencing binary as well. 0002So code sharing across different solutions is not possible with the Shared Project.

Refactoring is difficult with a Shared Project. 0002Any code within a preprocessor directive that is not a part of the active project will not be touched during a refactor. 0002That can lead to a mess very easily.

All of the preprocessor directives themselves can also lead to a real mess in your code.

How To Implement Shared Projects

Let’s get down to it and talk about0002how to implement a Shared Project. 0002One of the first things to know are the preprocessor directives. 0002For our purposes, we’re only interested in the ones associated with mobile projects:

  • IOS
  • ANDROID
  • WINDOWS_PHONE

Each directive is surrounded by two underscore characters. 0002It is also worth noting that0002specific versions of Android can be targeted with the following directive:

  • ANDROID_14

The code within the above preprocessor statement will only be compiled into applications targetingthe Android 14 level API and above.

Any code contained within the preprocessor directive will only be compiled into the platform the preprocessor directive is referring to. 0002Otherwise, using a Shared Project is no different than adding a “normal” class library into your solution.

Example

Let’s demonstrate this with an example. 0002Throughout this series of tutorials, we’ll be creating a Tabata app. 0002A Tabata is a high intensity interval exercise, where you exercise0002at a high intensity for a set amount of time, rest for a set amount of time, and repeat. 0002The app we’ll develop will let the user specify the exercise0002time, the rest time, and how many sets they want to do. 0002It will also keep a history of the Tabatas completed in a CSV file.

Sharing Projectsexplore ProgrammingMs project sharing

The first step in creating a shared code library is to identify the code which can be shared. 0002In our case, we’ll model the individual Tabata with properties of Date, Work Interval, Rest Interval and Number of Sets. 0002We’ll also have a list class which contains a history of all of the completed exercises and the ability to read them from the saved CSV file.

The next step is to create0002a solution that has both an iOS and Android project in it. 0002From there we’ll need to add a Shared Project. 0002That’s under the C# node in the “Add New Project” dialog box. 0002The naming convention usually follows Microsoft Project Sharing

We went through what exactly a Shared Project is, discussed the pros and cons of Shared Projects, how to implement them and a demoed quick code example. 0002The main thing to take away here is that Shared Projects enable you to use platform specific APIs in the same library referenced from projects targeting completely different0002platforms. 0002However, the Shared Project cannot be used outside of its current solution.

In the next post in this series of creating cross platform code, we’ll talk about Portable Class Libraries and how they stack up against Shared Projects.

Website Project – September 26, 2015

  • My First Website (CoderDojo Kata – download)
  • CSS Diner (GitHub – online game)

Just starting out?

  • Try the Hour of Code with programming puzzles based on Angry Birds or Frozen characters. (And get a certificate of completion at the end!)
  • Get more practice by doing the exercises on the Scratch Help Cards using the Scratch Online Editor or the Scratch Offline Editor.
  • Use your Scratch skills and imagination to create your own animation, game, or whatever!
  • Look at the exercises and project ideas in Beyond Hour of Code…

Tip: To make it easy to save and share your programming projects, create a login by clicking Join Scratch on the Scratch home page!

A little more advanced?

Project
  • Animate your name with Scratch.
  • Design a holiday card with Scratch.
  • Create your own Pong game with Scratch.
  • Solve Towers of Hanoi with Scratch.
  • Explore and remix your own Scratch Starter Projects.
  • Explore and remix your own Complex Scratch Projects.

Ready to learn other languages, web stuff, and fun stuff like writing mobile apps?

There are lots of more advanced tutorials and projects available on the web in whatever language you want to learn.

Here are a few you might want to check-out:

  • Codecademy – Learn JavaScript, HTML, CSS, jQuery, PHP, Python, Ruby, and how to program with web API’s.
  • Khan Academy
  • Learn to build an iOS app in an hour on Make School.
  • Learn to build an Android app with the MIT App Inventor.
  • Learn Google Apps Script.
  • Check-out some Java tutorials and references.
  • Find examples of cool code snippets that others have created:
  • Try things out and see what works in these online coding tools:

Tip: Try W3Schools to look-up syntax and explanations for language stuff you don’t know!

Pro Tip: Use Stack Overflow for the really tough questions and GitHub for version control / open source collaboration!

Want to help mentor and share what you know?

Do you already know all about programming, and want to start sharing what you know with others? We’re looking for volunteers and mentors!

Need advice on where to start?

Get in touch here or on Facebook – we’ll be happy to help point you in the right direction.

You can also try browsing our growing list of programming resources, tutorials, and websites.