As it stands, Visual Studio does not allow you to explicitly target a framework other than the .NET framework. I cover that in this post, so if you are curious about that, then you may want to go read that first to understand where this post is coming from. But thankfully, Jason left me a comment that pointed me to this post by Jonathan Pobst. It was a big help in researching this post and basically set me on the right path to getting things to where I wanted them.
The goal was to get some Mono project templates working with Mono assemblies and the Mono compiler in Visual Studio. The trick was to do it in a way that would be able to survive upgrades of Mono installations. I think I pulled it off.
The end result is a series of project templates that you can put in your \My Documents\Visual Studio 2008\Templates\ProjectTemplates\Visual C#\Mono directory that will give you the following New Project options:
Notice the Mono option on the left hand side of the dialog and the Mono project types in the right hand side. Yep, that’s the little Mono monkey there too.
In order to use these, you are going to have to do a few things:
1.) Download and install Mono. I installed the current release (2.2) to C:\Mono\2.2
2.) Add a MonoPath environment variable and have it point to C:\Mono\2.2\bin
3.) Add a MonoLibPath environment variable and have it point to C:\Mono\2.2\lib\mono\2.0
4.) Reboot so the environment variables will be recognized
5.) Grab the download at the end of this post and unzip it. In it, you will find 3 project templates and 1 file called Mono.CSharp.targets.
6.) Place the 3 project template files (.zip) in the \My Documents\Visual Studio 2008\Templates\ProjectTemplates\Visual C#\Mono directory. You’ll have to create the Mono directory.
7.) Now, grab the Mono.CSharp.targets file and place it in the C:\Mono\build directory. Again, you will have to create the build directory.
8.) Now, fire up Visual Studio and bring up the New Project dialog. You should see something similar to the New Project Dialog above. (Note: If you don’t see the Mono option in the left side of the dialog then you may need to add the Mono directory to the \My Documents\Visual Studio 2008\Templates\ItemTemplates\VisualC#\ directory as well – see here – otherwise, you may only see them at the top level C#.)
9.) Now, go ahead and select one. You will get prompted with the following prompt from Visual Studio. Make sure you select the Load Project Normally option.
That should about do it. You will now be creating Visual Studio projects that reference the MonoPath and the MonoLibPath, so as you upgrade and wish to move from version to version, all you should have to do it change your environment variables and you will be compiling against the latest version of Mono and using the Mono compiler. (Presumably something like C:\Mono\2.4)
Now, some may point out that Mono is binary compatible with .NET so what’s all the fuss? The answer is that they are in different stages of development, so if you target the .NET framework and then try to run on Mono, you may end up with some gotchya’s. For example, a class or method call that is not yet implemented in Mono. Whereas if you target Mono, then you can be pretty assured, when referencing a System.*.dll it will be implemented in .NET. Also, if you use any of the Mono.*.dll assemblies in your projects, you’ll can just drag them around like any other referenced assembly. There are about 20 Mono.*.dll assemblies, so there is bound to be some goodies in there.
If you already have Mono installed somewhere, then you should be able to point your environment variables to the relative locations of your installation and you should still be good to go.
While writing this, I was listening to "Jane Says" by Jane’s Addiction