Developing with MonoTouch on Windows and Visual Studio

Posted by ESCOZ on Thursday, January 28, 2010

Here’s how to develop with MonoTouch on Windows and Visual Studio 2008. You won’t be able to compile the code, as it depends on libraries that simply do not exist on Windows, but tools like Resharper will work perfectly. This will allow you to write the code faster, but you’ll still need the mac to run the app on the Simulator or the iPhone.

On the mac:

  1. Create a new project with MonoTouch
  2. Put it in a network share, or a code repository, so it can be accessed from Windows.

On Windows:

  1. Download 7-zip and install
  2. Download MonoTouch's trial version. We'll need one DLL from this package.
  3. Open the pkg file with 7-zip and go to this directory: monotouch-eval-1.4.7.pkg\monotouch.pkg\Payload\Payload~\.\usr\lib\mono\2.1\
  4. Extract all the DLLs to a directory of your choice (not inside the project).
  5. Make copies of your SLN and CSPROJ files, and call them "mysolutionVS.sln" and "myprojectVS.csproj"
  6. Edit your new mysolutionVS.sln:
    • Change the two references (at the top and bottom of the file) to point to the new myprojectVS.csproj.
  7. Edit your newmyprojectVS.csproj file:
    • Delete the "ProjectTypeGuids" line. In my case, the line to be deleted contains the following:
      <ProjectTypeGuids>{E613F3A2-FE9C-494F-B74E-F63BCB86FEA6};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
  8. Create a new file in the same directory called "myproject.csproj.user", with the following content:
    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
        <PropertyGroup>
            <ReferencePath>C:\path\to\monotouchlibrary\</ReferencePath>
        </PropertyGroup>
    </Project>
    The ReferencePath above should point to the directory where you saved the DLL files in step 3. Do not include the dll name.
  9. Open the new solution with Visual Studio.
  10. Finally, remove the current references in that the project contains, and add references to the DLLs from the directory in step 3.

That’s it! You’ll now be able to open the solution in Visual Studio, and use tools like Intellisense, Resharper and others to facilitate the development. To compile the app, use the original solution file in MonoTouch. If you add or remove files, make sure you add them again when you go back to MonoTouch.

While I prefer to make these changes manually, as they’re quite simple, that may not be the case for you. In that case, Manfred Pohler created a little application that automatically does it for you, called VSMTouch. I haven’t used it, but it seems to do something similar to the steps above.