Mac app build option unavailable

I'm struggling to find a clear answer to that simple question : what's the path to build an OSX app from a VS c# project?

I tried and read about everything...

  • Original project : C# windows form in Visual Studio. .Net framework 4.5
  • Open and run perfectly in Mono or Xamarin Studio.
  • Checked compatibility with Mono Migration analyser : everything fine.
  • Installed Xamarin Studio enterprise
  • Still no Mac app build option in the project options.

Is such thing possible or not? If so, where's the mac build option? I'm lost on that issue...

Best Answers

Answers

  • So, I understand that the only path to build something usable on OSX without redesigning (natively) everything is to run an exe of my solution with Mono. Right?

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai
    edited March 2017

    Since it was requested off thread, here's the strategy I'd use to "port" an existing .NET application to macOS.

    Step 1 - Extract out as much functionality as possible to shared libraries that do not depend on platform functionality.

    • Often business logic, how to respond and process various requests, get bound up inside UI logic and callbacks
    • To make code sharing easier between the platform, you need to extra this into a class library you can share between the two platforms.
    • I would start by making a class library, adding it as a main reference to your application, and slowly moving logic to it.
    • With each step, make sure you did not break things. If you do not a strong automatic test suite (or one at all), this will involve a lot of manual testing.
    • If the functionality does not require state, you can use simple static methods. However, as your shared code library continue to grow or begins to contain state, adopting a pattern like MVC or MVVM (which you can do without data binding).

    Step 2 - Move to a Mac and get your shared library building.

    • Next to your Windows solution (or inside, depending on how separate you want the two) create a Xamarin.Mac Project.
    • It'll start targetting Xamarin.Mac Mobile (Modern). Depending on what libraries you need to depend upon, this might work just fine.
    • However, if you need to depend on many 3rd part or nuget libraries, you make need to swap it to XM 4.5 (Full). See the documentation linked.
    • If you are sticking with Mobile (Modern), create a new Xamarin.Mac Library project, and add to it all of your lib files. If you are using XM 4.5 (Full), you can add your existing library project to the solution.
    • In any case, have your Xamarin.Mac App project reference your lib
    • Work on getting things to build. You might have to remove functionality that is Windows specific if it slipped into your shared code
    • If you happen to have a test suite, getting it passing here is incredibly useful. If you don't, you really should pencil in time to write one

    Step 3 - Write the UI and Mac specific code

    Step 3.1 - Write or expand auto tests.

    • Developing on an application which is cross platform has its own challenges. UI testing can be rather hard, but having a solid test suite for your shared logic can pay great dividends.
    • Nunit is the standard testing framework for Xamarin.Mac (and Xamarin.iOS).

    One nice benefit to this work is that it makes adding additional platforms significantly easier. Say one day you want a WPF or UWP version of your application with more modern Windows chrome, or an iOS or Android port. You've already done half the work by breaking out your business logic to a shared library.

Sign In or Register to comment.