In the Registry Editor, navigate to: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SKUs\ and create a new Key folder called .NETFramework,Version=v4.0,Profile=Mono

Now navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\v4.0.30319\SKUs\ and create the same Key folder again here (this step is only necessary for x64 machines, but since all software developers use those then you’ll probably need to do it!)

Now load up VS2012 and a project. Goto the Project Properties (Alt+Enter whilst having it selected on Solution Explorer) .

Choose the Application tab on the left and look for the “Target framework” drop-down list.

On this list you should see an entry called “Mono 2.10.9 Profile”.

Select it, and Visual Studio should then convert your project to target the Mono framework. You’ll notice that it will re-reference all your various System assemblies and if you study the filenames they will point to the Mono ones that were created during Step #3.

Note: I was scratching my head at first as I kept getting an error from Visual Studio saying:

This application requires one of the following versions of the .NET Framework: .NETFramework,Version=v4.0,Profile=Mono

Do you want to install this .NET Framework version now?

Turns out that even on a x64 machine you MUST add both Registry key SKUs (see Steps #7 and #8). It is not enough to just add the Wow6432Node key, you must add the other as well. I can only assume this is because VS2012 is a 32-bit application. But maybe it’s also affected by whether you’re compiling to Any CPU, x64 or x86… who knows. It doesn’t really matter as long as this fixes it, which it does!

Building and executing your first program

Now that your development environment is nicely setup, you can proceed and build your first program.

The Mono equivalent of MSBuild is called XBuild (not sure why they didn’t call it MBuild or something!). You can build your .csproj by doing the following:

Load the Mono Command Prompt (it will be on your Start Menu/Screen, just search for “mono”).

Change directory to your project folder.

Execute the following command to build your project using the Mono compiler:$ xbuild /p:TargetFrameworkProfile=""Note: You must specify the blank TargetFrameworkProfile parameter as otherwise the compiler will issue warnings along the lines of:

Unable to find framework corresponding to the target framework moniker ‘.NETFramework,Version=v4.0,Profile=Mono’. Framework assembly references will be resolved from the GAC, which might not be the intended behavior.

Hopefully you’ll not have any errors from the build…

Now you can run your program using the Mono runtime, to do this:$ mono --gc=sgen "bin\Debug\helloworld.exe"Note: You'll definitely want to use the "Sgen" garbage collector (hence the parameter) as the default one in Mono is unbearably slow.

You can do a quick “smoke test” to verify everything is in order with both your compilation and execution. Have your program execute something like:Console.Write(typeof (Console).Assembly.CodeBase);
… and this should print out a path similar to:file:///C:/PROGRA~2/MONO-2~1.9/lib/mono/4.0/mscorlib.dll
I’ve no idea why it prints it out using 8.3 filename format, but there you go! You’ll notice that if you run your program outside of the Mono runtime then it will pick up the Microsoft CLR version from the GAC.

I was trying to use Mono profiles from my Visual Studio 2010 installation and this article points me in the right direction; I was missing the registry key entries.

In my case, I wanted to maintain differents mono profile versions working inside VS2010, so I made a few modifications that may be useful to others to know.

In point 3, I create a directory with the name “Mono_2.10.9” (instead of a Mono directory/link). That difference must be taken into account when creating the registry keys, so, my registry keys for my installation is: “.NETFramework,Version=v4.0,Profile=Mono_2.10.9” instead of “.NETFramework,Version=v4.0,Profile=Mono”

Also in point 5, the xml file should be different across the varios versions for “Name” and “Redist” attributes of “FileList” node.

After I use Xbuild, it gives me 52 errors and 0 warnings saying that “Not Valid As An Identifier”. I’m using Visual Basic 2010 Ultimate. Also when I change my project to the Mono Profile, I get 11 errors in Visual Studio. Like “ShutDownStyle” is not a member of XXX.

Nathan,
My pc is 32bit with WinVista and Visual Sudio is 2005. I followed point 8 up to HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft and do not see .NETFramework. Now is there anything equivalent for 32bit machines to what you suggested?
Thanks,
Homeyra

Very confusing – I am trying to port a legacy C# on Windows project to Mac. Installing the Mono framework went fine. It builds without problems on VS 2012 targeted to mono-4.0.1 and I can run it in the command line box with mono. On Xamarin I have problems. I can build it with one warning when I target at .net run-time and use msbuild. If I target it at mono 4.0.1 run-time I get one error. If I use xbuild, I get 7 errors even if I build using xbuild directly in the command line box. All errors relate to resource files of graphical objects not being found. Is mono buggy? is Xamarin buggy?

“xbuild is not recognised as an internal or external command, operable program or batch file” error on the Mono command prompt. I tried changing env variable Path to the C>Windows>Microsoft.NET>Framework>v4.030319;
Does not help. any idea why?