Nathan Evans' Nemesis of the Moment

Targeting Mono in Visual Studio 2012

Posted in .NET Framework, Unix Environment, Windows Environment by Nathan B. Evans on February 13, 2013

These steps are known good on my Windows 8 machine, with Visual Studio 2012 w/ Update 1 and Mono 2.10.9.

  1. Install Mono for Windows, from
    Choose a decent path, which for me was C:\Program Files (x86)\Mono-2.10.9
  2. Load an elevated administrative Command Prompt (Top tip: On Windows 8, hit WinKey+X then choose “Command Prompt (Admin)“)
  3. From this Command Prompt, execute the following commands (in order):
    $ cd "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile"
    $ mklink /d Mono "C:\Program Files (x86)\Mono-2.10.9\lib\mono\4.0"
    $ cd Mono
    $ mkdir RedistList
    $ cd RedistList
    $ notepad FrameworkList.xml
  4. Notepad will start and ask about creating a new file, choose Yes.
  5. Now paste in this text and Save the file:
    <?xml version="1.0" encoding="UTF-8"?>
    <FileList ToolsVersion="4.0" RuntimeVersion="4.0" Name="Mono 2.10.9 Profile" Redist="Mono_2.10.9">
  6. From the same Command Prompt, type:
    $ regedit
  7. 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
  8. 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!)
  9. Now load up VS2012 and a project. Goto the Project Properties (Alt+Enter whilst having it selected on Solution Explorer) .
  10. Choose the Application tab on the left and look for the “Target framework” drop-down list.
  11. On this list you should see an entry called “Mono 2.10.9 Profile”.
  12. 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:

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:

  1. Load the Mono Command Prompt (it will be on your Start Menu/Screen, just search for “mono”).
  2. Change directory to your project folder.
  3. 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.

  4. Hopefully you’ll not have any errors from the  build…
  5. 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.
  6. 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:
    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.

17 Responses

Subscribe to comments with RSS.

  1. trk said, on February 15, 2013 at 2:59 PM

    Point 11. does not work for me (VS2012 v.11.05 Update 1, 64bit pc) . “On this list you should see an entry called “Mono 2.10.9 Profile”. I can’t

  2. trk said, on February 15, 2013 at 3:38 PM

    Ok I found. RedistList directory shoud be inside Mono directory.
    In point 3 shoud be added (after mklink line) :
    $ cd “C:\Program Files (x86)\Mono-2.10.9\lib\mono\4.0”

    thanks good tutorial.

    • Nathan Evans said, on February 15, 2013 at 4:51 PM

      Thanks, not sure how that got missed. Have updated the article.

  3. Enrique said, on April 18, 2013 at 9:48 AM

    Hi Nathan,

    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.

  4. Kris Milan said, on June 30, 2013 at 8:50 PM

    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.

  5. Alaa Joseph said, on July 1, 2013 at 6:39 PM

    What to here : [ xbuild /p:TargetFrameworkProfile=”” ] ?!
    I mean what’s the Target frame work ?

    I tried “Mono” and other several things but all didn’t work.

    And thank you for this guide.

  6. writz said, on July 18, 2013 at 9:59 AM

    I want to set up .NET 3.5 with Mono. What can I do?

  7. Homeyra said, on October 3, 2013 at 3:42 PM

    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?

  8. RationalGaze said, on December 23, 2013 at 1:16 AM

    Tested & worked. Thanks a lot !

  9. Kumar C said, on July 7, 2014 at 10:51 AM

    Great Article. But Works only with Windows Application. Does not show the Mono in the target frame work when trying to change for ASP.NET applications.

    • Kumar C said, on July 7, 2014 at 10:52 AM

      Also does not work (Windows or Web) for 3.5. Worked for 4.0 only.

  10. Ralph Bloch said, on May 21, 2015 at 3:52 PM

    I followed your steps (but for Mono version 4.0.1). After building the application I ended up with the identical output as I did when I compiled for Target .Net 4.0

  11. Ralph Bloch said, on May 22, 2015 at 3:16 PM

    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?

  12. Shraddha said, on July 13, 2015 at 6:57 PM

    “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?

    • M Adeel said, on February 9, 2016 at 7:17 AM

      install mono, install monohelper extension, do the configurations as mentioned, run it with xbuild in monohelper. everything gonna be fine. I’ve tested it on win8.1

  13. NIKHIL SEHGAL said, on November 10, 2016 at 12:25 PM

    Dose it work with Mono framework 4.6.1(.net Framework 4.6.1)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: