Wednesday, 19 December 2012

How to: Building the mg-desktop viewer from source

If you have/are using mg-desktop for your own MapGuide desktop applications, you're most likely working with the map viewer component most of the time. If you want to hack your own customizations into this map viewer outside of the provided extension points or to fix any viewer bugs, you have to be able to build this viewer from source.

Unfortunately, building mg-desktop from source is a complex multi-step affair like its MapGuide Server/Web counterpart, that requires a full checkout of the entire MapGuide source tree:

  1. We need to build FDO and/or setup the binary SDK in the correct path under MgDev\Oem
  2. We need to build the MapGuide Oem stack
  3. We need to build the MapGuide and mg-desktop shared C++ components and SWIG bindings
  4. Finally, we need to build the mg-desktop .net components
Assuming you just want to hack around with the mg-desktop .net viewer component source, there is a way to skip steps 1-3 and avoid the full checkout. This post will show you how.

We'll demonstrate using the Express Edition of Visual Studio 2012 for Windows Desktop in conjunction with the .net 4.0 build of mg-desktop. For the .net 2.0 build, you will need Visual Studio 2008 instead.

Firstly, grab the latest mg-desktop binaries.

Then, do a subversion checkout of the MgDev\Desktop directory under the 2.4 branch (as this is the source branch used to produce the latest mg-desktop binaries). The SVN checkout URL for this is:

Note that checking out this directory will only let you build the viewer source (the objective of this post). You cannot build the full mg-desktop set of binaries from this directory. To do that would require checking out its parent (MgDev) instead and doing the full 4 builds steps, which will take some time.

In your fresh SVN checkout, create a bin directory

Inside this bin directory, create a release directory (for 32-bit). For 64-bit, use release64

In the latest binaries zip file, extract the files under the Desktop directory to your release or release64 directory, which should now look like this after extraction

Back in the bin directory, create an Assemblies directory and move the following files from release/release64 into this directory:
  • OSGeo.MapGuide.Foundation.dll
  • OSGeo.MapGuide.Geometry.dll
  • OSGeo.MapGuide.PlatformBase.dll
  • OSGeo.MapGuide.Desktop.dll
In addition, copy the related XML files as well if you want intellisense on these assemblies

You have now replicated the binary output that steps 1-3 would've produced on a full SVN checkout, so now we can go straight to step 4 and open the mg-desktop .net solution file in Visual Studio:
  • MgDesktopDotNet.sln if you're using the .net 2.0 build and VS 2008
  • MgDesktopDotNet_VS2010.sln if you're using the .net 4.0 build and VS 2010 or VS 2012
Make sure the platform configuration matches the bitness of your mg-desktop binaries, otherwise you'll get BadImageFormatException trying to debug any of the executable projects.

Once that is set, you can now build the entire .net solution. Updated viewer component assemblies will be under bin\release for 32-bit and bin\release64 for 64-bit

Now the viewer is ready to be hacked around. The projects you probably be most interested in are:
  • MapViewer - Contains the source for the mg-desktop viewer component
  • MapViewer.Desktop - Contains the source for the mg-desktop implementation of MgMapViewerProvider
  • MapViewerTest - A test WinForms application that embeds the map viewer component.
  • MgAppLayout - The App Layout Engine front-end executable
For the VS2010 solution, these projects are suffixed with .Net40

Happy hacking/debugging.


Bauer50 said...

Have you ever complied, or attempted to compile, mg-desktop for mobile, such as an Anroid Tablet or iPad?

Jackie Ng said...

Nope. Because:

1. I don't have a Mac
2. Nobody has tried and/or reported success on building the MapGuide core (which mg-desktop is built on top of) on a Mac

Bauer50 said...

Ok. I don't have a Mac either. I was looking at using Monodroid or Monotouch but they are wanting so much for the business package for a "maybe". I think I will go the OpenLayers with PhoneGap route until the new MapGuide 2.6 with the new Fusion comes out with the mobile support as you stated in one of your other posts. Thanks for the info.