Visual Studio alternatives for Mac

I want to use C# but Visual Studio does not exist for Mac. Am I stuck with a text editor?

Besides running Visual Studio in virtualization software (Parallels, VMware etc) you have the choice of using MonoDevelop. With the recent 2.2 beta releases it has reached a level where it is usable for daily production.

It can be found here: http://monodevelop.com/

It is a full featured IDE similar to Visual Studio, features all the nifty things you are used to like intellisense. Best of all it is free, reads visual studio solution/project files etc.

It is not (yet) bug free, but it is already much much better than using a text editor

As a bonus info Unity is actively involved in making MonoDevelop better and usable.

Personally, I really think the only "alternative" to Visual Studio on the Mac is ... Visual Studio ;-) ... see also the Setting up Visual Studio for Unity (that article was from before there was Unity for Windows, so while it's a little dated in parts it deals with a lot of the issues involved in setting this up in a virtual machine).

There's also a "hack" to make Visual Studio open the file you clicked on in the virtual machine, in Visual Studio (including opening the correct solution file generated by the Unity-Visual Studio integration). This hack is based on the solution provided in Windows version: integrate with Visual C# (which is redundant for Windows since Unity 2.6 but still very relevant for the Mac OS version of Unity). Not sure if this works in Parallels, but in VMWare, it does: You can open Windows-applications directly from Mac OS; so you need to create a build of a modified version of what's posted in that thread and create a symlink from Unitron to that application (yeah, you do replace Unitron that way ... and you'll have to "fix it" each time a Unity update "broke it").

With that, you can open the correct solution in Visual Studio, and jump to the correct file. In my case, I convert the path I'm getting in VMWare from the Mac-side to the local, network-based path I'm using in my virtual machine (this can easily be done in the solution posted by ToreTank). What I'm getting is something like

\\.host\Shared Folders\somepath\Assets\somepath\MyScript.cs

which I convert to:

I:\somepath\Assets\somepath\MyScript.cs

What's still missing is jumping to the right line number. Unfortunately, that's far from being trivial and will require some Cocoa/Objective-C coding (that's where I got stuck): There's a protocol used by Unity to "tell" Unitron the line number (according to Benoit Fouletier that is the ODB protocol which is used by any BBEdit-compatible editor, including Smultron which is what Unitron is based on). Basically, what we need is a little Cocoa application that mimics this protocol, gets the line number from Unity, puts it into a file that the "helper application" in VMWare reads when it opens the file in Visual Studio, and finally launches the "helper application" on the VMWare-side (which - from Mac OS - looks like a Mac OS application).

The reason you need to store the line number into a text file is that you can only pass file-paths as parameters from Mac to VMWare (you cannot pass a "line-number argument" - but you can have a "common communications file" into which the Mac application writes and from which the Windows-side wrapper reads).

One solution might be simply hacking Smultron (which is open source) to do what we need. If anyone wants to try this: In the Smultron project, look for the method "shouldOpen" in Classes/Performers/SMLOpenSavePerformer.m. Pretty much at the end of this method, there's this kind of code:

if (appleEventSelectionRangeDescriptor) {

        AppleEventSelectionRange selectionRange;
        [[appleEventSelectionRangeDescriptor data] getBytes:&selectionRange length:sizeof(AppleEventSelectionRange)];
        NSInteger lineNumber = (NSInteger)selectionRange.lineNum;

        if (lineNumber > -1) {
            [[SMLTextMenuController sharedInstance] performGoToLine:lineNumber];
            // here's where we'd have to hook into
            // add magic to store line number to file and open VMWare-wrapper here
        } else {
            // [not relevant for our purposes]
        }
    }

That's about as far as I got with this; not a complete solution - but I'd say "pretty close".

I think it would be really nice to get a full solution which is "as clean as possible" that we could post to the Wiki. I'll be happy to provide the Windows-side wrapper (credit goes mostly to the people who posted in the above mentioned forum posting - I just did some tweaks on it and would be happy to implement the final steps needed). With that, after a little bit of initial setup, you'll be able to use Visual Studio with Unity on the Mac almost exactly as conveniently as you do on Windows.

MonoDevelop has been steadily improving, and while still significantly clunkier than TextMate, it is now usable and does have some very appealing features:

  • IntelliSense
  • NUnit support
  • Some limited refactoring options
  • Auto-completion of repetitive tasks, like the C# standard for documenting code parameters
  • Code region collapsing and expansion

You can also read this question for details on how to set it up.