Creating Mac OS X applications with MS Visual Studio Express
use Visual Basic Express, Visual C# Express, Visual C++ Express or Visual J# Express to write applications for OS X

Creating OS X applications with MS Visual Studio Express

This tutorial is based on Toki Kanno’s article, used (and translated) with permission.

This tutorial teaches you how to write a Mac OS X application with Microsoft Visual Studio Express (Visual Basic, Visual C#, Visual C++ or Visual J# Express). This article is not to suggest replacing Apple's Xcode with Microsoft Visual Studio, but in hope to provide Visual Studio programmers a faster way to port Windows applications to Mac OS X.

Before we start

In order to write an OS X application from Windows environment, you will need following environment and tools:
  1. Microsoft .NET Framework
    You will need Microsoft .NET Framework installed on the Windows machine you wish to create application with. If your Windows installation does not have .NET Framework installed, you should install it from Windows installation disc.

  2. Microsoft Visual Studio Express
    Visual Studio(Visual Basic Express, Visual C# Express, Visual C++ Express or Visual J# Express)
    Microsoft offers Visual Studio 2005 Express Edition for free, you can get it from this MSDN page.
    We use Visual C# 2005 Express for this tutorial.

  3. Mono Framework Mac OS X binary package
    Mono is an open source project that provides the necessary software to develop and run .NET client and server applications on Linux, Solaris, Mac OS X, Windows, and Unix. The .NET Framework uses Common Language Infrastructure (CLI) Virtual Machine (similar to Java VM). Applications that comply Common Language Runtime (CLI) standard should run correctly on any targeted platform as long as there's a CLI Virtual Machine installed.
    You can download Mono Framework for Mac OS X from Mono Framework homepage.

  4. wx.NET binary package for Win32 and Mac OS X
    wx.NET is a .NET Common Language Infrastructure (CLI) wrapper for wxWidgets. We choose wxWidgets because it is easier to use than use Mono’s System.Windows.Form.
    You can download wx.NET from http://wxnet.sourceforge.net/

Start writing an application

  1. Creating a Visual Studio project
  2. To create a new Visual C# project, select Empty Project and name the proejct wx.Test.
  3. Add references to the project

  4. Make sure System and System.Drawing (under .NET tab) are added. We also need to add wx.NET.dll.


    It should look like following screenshot:


  5. Write the source code
  6. Just go through Project > Add New Item, and select MaiinForm.cs.

    To make the life easier, we provide following simple code. If you don’t want to type the code yourself, you can download the source code here.
    using System;
    using System.Drawing;
    using wx;
    
    public class MainForm : wx.Frame
    {
        public MainForm()
            : base("Test Application", new Point(0, 0), new Size(100, 100))
        {
        }
    }
    
    public class MainApp : wx.App
    {
        public override bool OnInit()
        {
            MainForm mainForm = new MainForm();
            mainForm.Show(true);
            return true;
        }
    
        [STAThread]
        static int Main(string[] args)
        {
            MainApp app = new MainApp();
            app.Run();
    
            return 0;
        }
    }

    Let’s can test the application by pressing F5 key. You should have an empty 100 by 100 pixel window as screenshot below.

    If you receive “cannot find wx-c.dll” error, you can find the file under wx.NET\bin folder. Simply copy it to Windows\System32 folder.
    Just to make the application look nicer. To get rid of DOS window, just open Project menu, and select wx.Test Properties, we can set the Output type to “Windows Application”.


  7. Install Mono Framework on Mac OS X
  8. Simply open the dmg file downloaded from Mono Project website, and install it.


  9. Creating the application for OS X
  10. We will need to manually build an OS X application in OS X app structure. To create one, just type following commands in Terminal:
    mkdir wx.Test.app
    cd wx.Test.app
    mkdir Contents
    cd Contents
    mkdir MacOS
    Next, we need to copy wx.Test.exe file to the MacOS folder we just created. (The wx.Text.exe is the one under bin\Release folder)
    Please also copy wx.NET.dll and wx.NET.dll.config (from wx.NET) to the MacOS folder.
    Next, we will need to create a plain text file with execute (755) permission and name it wx.Test, with following content:
    #!/usr/bin/perl
    $appmain = "wx.Test.exe";
    
    use File::Basename;
    $scriptdir = dirname($0);
    
    chomp($nowdir = `pwd`);
    $realapppath = "$nowdir/$scriptdir/";
    $realappname = "$realapppath$appmain";
    
    $ENV{DYLD_LIBRARY_PATH} = "/Volumes/wx.NET-0.7.2-MacOSX-Build/Bin/:$ENV{DYLD_LIBRARY_PATH}";
    
    chdir ($realapppath);
    exec ("mono $realappname");
    Where $ENV{DYLD_LIBRARY_PATH} defines the path to wx-c.dylib, you should adjust the line to accommodate your installation.

    To change the wx.Test file to 755 permission, you can use Get Info window or following command:
    chmod 755 wx.Test

It’s all done now; you can run the application.




Please be advised, you will need Mono Framework installed on Mac OS X to run application created with Microsoft Visual Stuido Express.

Join our discussion at SillyDog701 Message Centre.

This article is based on Toki Kanno’s article in Chinese. It has been translated and re-organised. I’d like to thank Toki Kanno for sharing this with us.

Antony Shen. http://mac.sillydog.org/dev/visual_studio.php This page was first released on 16 September, 2006,last updated on 10 March, 2007.
Copyright © 2006 Antony Shen and Toki Kanno. All rights reserved.