Blog moved to http://www.andrevdm.com/

Tuesday, 28 May 2013

Building for mono and Microsoft .NET

Recently I wanted to build my project on mono and Microsoft .NET. What I wanted to do was
  1. Build on windows using Microsoft .NET as per usual
  2. Build using mono on windows
  3. Build using mono on linux
  4. Use nuget package restore on all three
Getting this all working was not terribly difficult but I did have to do a fair amount of googling. Here is what I needed to do to hopefully this will save someone some time.

Installing the latest version of mono
Windows:
  1. Download the 3.x from http://www.go-mono.com/mono-downloads/download.html
  2. Create dmcs.bat in C:\Program Files (x86)\Mono-3.0.10\bin as this is missing in the latest download
    1. See https://bugzilla.xamarin.com/show_bug.cgi?id=8813
    2. REM dmcs.bat compatibility shim for mcs
      @echo off
      call mcs -sdk:4 %*
Linux:
  1. See http://www.meebey.net/posts/mono_3.0_preview_debian_ubuntu_packages/

  2. Add this line to your /etc/apt/sources.list file:
       deb http://debian.meebey.net/experimental/mono /

  3. apt-get update
  4. apt-get install mono-complete




Creating a mono solution and projects

Mono’s xbuild is not yet 100% compatible with msbuild. MonoDevelop is also not 100% compatible with the VS 2012 solution/project format. So to make my life easier I’ve written a simple C# script that generates mono solutions and projects from the VS2012 ones.

This is pretty simple and works really well. It also means I can easily have separate output folders for the windows and mono binaries.

Get the source from my gist at https://gist.github.com/andrevdm/5655285#file-updateprojectfileversion-cs




Getting NuGet & package restore working on linux
  1. Import the required certificates
    1. See http://stackoverflow.com/questions/15181888/nuget-on-linux-error-getting-response-stream/16589218#comment24184791_16589218
    2. sudo mozroots --import --machine --sync
    3. sudo certmgr -ssl -m https://go.microsoft.com
    4. sudo certmgr -ssl -m https://nugetgallery.blob.core.windows.net
    5. sudo certmgr -ssl -m https://nuget.org

  2. Create a mono specific NuGet.target

      1. See http://nuget.codeplex.com/SourceControl/changeset/view/0b1e224884a3#src/Build/NuGet.targets

      2. Or use my version (minor modifications) that works with the project generator above
        https://gist.github.com/andrevdm/5660800#file-nuget-mono-targets

There is also some great info on NuGet here

  1. http://www.lextm.com/2013/01/how-to-use-nuget-on-mono-part-i.html
  2. http://www.lextm.com/2013/01/how-to-use-nuget-on-mono-part-ii.html
  3. http://www.lextm.com/2013/02/debugging-on-mono-xbuild-issue.html





Build scripts

Finally to wrap it all up here are build scripts for linux and windows


Linux
#!/bin/bash
export EnableNuGetPackageRestore=true
mono ./makeMonoProjectsAndSln.exe MySolution.sln
xbuild /p:TargetFrameworkProfile="" MySolution.mono.sln




Windows
@echo off

makeMonoProjectsAndSln.exe MySolution.sln

"C:\Program Files (x86)\Mono-3.0.10\bin\xbuild.bat" /p:TargetFrameworkProfile="" MySolution.mono.sln

No comments:

Post a Comment