For those who don’t know, Visual Studio 2010 is a piece of software known as an IDE (Integrated Development Environment), IDE’s are used to make programming easier. Visual Studio is arguably the best IDE available however is only for developing on Microsofts .NET framework (basically means you can only code for windows, windows phone 7 [presumably 8 aswell] and xbox 360). If you didn’t get any of that then stop reading.
Some time ago microsoft revealed some details about the inner workings of the .NET framework, enough so that the mono project was spawned. For all intents and purposes the mono project is .NET for mac, windows, linux, BSD and PS Vita. For an additional fee of $399 each you can have iOS and android support.
Lovely but the mono compilers either need invoking through the command line (and that can be a major faff) or you can use mono-develop which is a god awful IDE in my opinion. There are also some plug-ins for netbeans and eclipse out there. If only we could use Visual Studio….
Oh wait 2 seconds. We can.
Well theres 2 ways really.
1) Target .net version 2 and make sure not to use anything like P/Invoke etc and the compiled .exe MAY run under mono anyway.
2) Add mono as one of the supported compiler targets in visual studio.
Option 2 will work with Visual C# Express and all paid versions of Visual Studio 2010 only. Visul Basic.Net Express and Visual C++ do not have mono specific compilers yet so although this technique will show mono as a supported compiler option it will give an error message every time you try to.
So, we’ll assume your using this for C# anyway and continue (and hope that there is a solution for the VB guys in future).
Download mono profile from here: http://greghurlman.com/wp-content/uploads/2010/10/monoprofile2_8.zip (courtesy of Greg Hurlman, I will ammend the post to show how to install find the profile on your own system in future, I’m just on holiday right now and can’t install mono on this machine/don’t have it already)
Extract the zip file to one of the following directories:
- 32 bit systems: C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile
- 64 bit systems: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile
In your Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile folder you should now have a folder named “Mono” assuming you used the exact filepaths I gave above.
Now the mono compilers are in the correct location for visual studio, now we just need to tell visual studio where they are. You will need admin rights for this and I highly advise getting the computer owners permission.
Hold the windows key on your keyboard and the R button, this will open the run dialog.
Type REGEDIT and press enter/return.
On the left hand side you should see a basic folder structure. Navigate to one of the following:
- On 32 bit systems: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\
- On 64 bit systems: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\
Right click The SKU’s folder and click new>Key
Give this new folder the name: “.NETFramework,Version=v4.0,Profile=Mono” and press enter. Then simply click File>Exit (do it this way to ensure the keys are saved properly)
Restart visual studio if it was open already and locate one of your C# projects or create a new one (using .NET v4 client profile)
Click Project>Properties. In the Application tab presented there should be a drop down box labelled “Target Framework”. Mono will now be in the bottom of it.
The .exe and .dll files now produced by visual studio will be for the mono framework not the .net framework. This doesn’t matter as .net will run them fine (although vice versa is not always true), a mac or linux system running mono (most linux systems do already) will now be able to run your code created in visual studio.
For .net and mono incompatibilities etc consider reading these links:
Information about using winforms (one of the GUI tools supported in visual studio) is here:
Winforms on mono can be fully functional but is a little dodgy. For a mac, windows and linux GUI toolkit you can use GTK#, the Visual Studio designer won’t fully support it but there are workarounds for that.
Now go forth and write cross platform programs in the best IDE ever