Farseer Physics Samples on Visual Studio 2015 (MonoGame)

In a hurry? Jump to: TL;DR.

Make sure you have installed the latest MonoGame. The version I’m using is 3.5 (for Visual Studio installed using the official installer, not NuGet).

The Farseer Physics Engine is a C# Box2D port that’s very popular among C# developers, it’s hand-optimized and believe it or not, it performs even better than the actual Box2D… well, at least when comparing Farseer 3.2 to Box2D 2.2 (the ported version), but I really doubt those numbers changed substantially.

The current Farseer version is 3.5, it’s somewhat old (Aug 2013) but it’s bug-free (afaik) and fully usable, the only real problem is that the samples won’t work with Visual Studio 2015. If you just want to give it a try that’s a problem.

To get the latest version, access the official page (link) and click the big “Download” button:

dlfarseer

The file you’re downloading is called “Farseer Physics Engine 3.5 Samples” but it doesn’t contain only the samples but the actual engine too. After downloading the archive, extract its contents somewhere in your disk, you’ll get a lot of solution files and folders too, there are solutions for XNA, Xbox360, WP7, which are all pretty much dead tech by now, and the one we’re interested in: MonoGame.

After opening that solution in Visual Studio 2015, the first thing you want to do is to set the “Samples MonoGame” as the StartUp Project, to do that, right click on it in the Solution Explorer and select “Set as StartUp Project” on the menu, as the image below, note that its name turns bold in the Solution Explorer view:

setstartup

If you try to run it at this point, a lot of errors will appear:

errors1

To fix that, expand all “References” from all projects, and remove the MonoGame.Framework (right-click and select “Remove”) please note that you have to remove from all 3 projects (screenshot shows only two):

reffix

Now re-add them pointing to the correct resource, to do that, right click over “References” and select “Add Reference”, then on the dialog that appears, browse the correct MonoGame Assembly, in my case it’s in the default install directory (C:\Program Files (x86)\MonoGame\v3.0\Assemblies\Windows):

addref

Select it and add to all the 3 projects, please note that you only have to browse the dll once because there’s a “Recents” list so for the other 2 times you just have to tick it.

At this point you may have noticed that there’s a reference to Tao.sdl that is marked with an exclamation mark, that’s because VS couldn’t find it, you can just remove that because it only exists for SDL support, if you want to fix it instead, you can get it here, but it was even removed from WinGL so even if you fix it I don’t know if you’ll to be able to use the SDL backend with recent MonoGame versions.

If you try to run it now, you’ll get errors regarding the .NET Framework version you’re using, to fix that, right-click on all projects, select “Properties”, and on the settings tab that appears, select a newer .NET Framework (I’ve selected 4.5). Do this for all 3 projects:

fixversion

Now if you try to run it, it will complain about SDL, this one is easy to fix, right-click on SDL.dll and remove it too:

remsdl

You should be able to run it now:

running

TL;DR: Too Long; Didn’t Read
You can download the updated project with the solution file updated to VS2015 here:

DOWNLOAD: Farseer Physics Engine 3.5 Samples for VS2015

sln

3 thoughts on “Farseer Physics Samples on Visual Studio 2015 (MonoGame)

  • I tried to compile but I got these errors:
    Severity Code Description Project File Line Suppression State
    Error CS0006 Metadata file ‘E:\Dropbox\Corsi 16-17\C&G\Exercises\Utilities\Farseer\Farseer Physics DebugView 3.5\bin\WindowsGL\Debug\DebugView MonoGame.dll’ could not be found Samples MonoGame E:\Dropbox\Corsi 16-17\C&G\Exercises\Utilities\Farseer\Farseer Physics Samples 3.5\CSC 1 Active
    Error CS0006 Metadata file ‘E:\Dropbox\Corsi 16-17\C&G\Exercises\Utilities\Farseer\Farseer Physics Engine 3.5\bin\WindowsGL\Debug\FarseerPhysics MonoGame.dll’ could not be found DebugView MonoGame E:\Dropbox\Corsi 16-17\C&G\Exercises\Utilities\Farseer\Farseer Physics DebugView 3.5\CSC 1 Active
    Error CS0006 Metadata file ‘E:\Dropbox\Corsi 16-17\C&G\Exercises\Utilities\Farseer\Farseer Physics Engine 3.5\bin\WindowsGL\Debug\FarseerPhysics MonoGame.dll’ could not be found Samples MonoGame E:\Dropbox\Corsi 16-17\C&G\Exercises\Utilities\Farseer\Farseer Physics Samples 3.5\CSC 1 Active
    Error CS0433 The type ‘FileMode’ exists in both ‘MonoGame.Framework, Version=3.5.1.1679, Culture=neutral, PublicKeyToken=null’ and ‘mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’ Farseer Physics MonoGame E:\Dropbox\Corsi 16-17\C&G\Exercises\Utilities\Farseer\Farseer Physics Engine 3.5\Common\Serialization.cs 39 Active
    Error CS0433 The type ‘FileMode’ exists in both ‘MonoGame.Framework, Version=3.5.1.1679, Culture=neutral, PublicKeyToken=null’ and ‘mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’ Farseer Physics MonoGame E:\Dropbox\Corsi 16-17\C&G\Exercises\Utilities\Farseer\Farseer Physics Engine 3.5\Common\Serialization.cs 27 Active
    Error CS0433 The type ‘FileMode’ exists in both ‘MonoGame.Framework, Version=3.5.1.1679, Culture=neutral, PublicKeyToken=null’ and ‘mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’ Farseer Physics MonoGame E:\Dropbox\Corsi 16-17\C&G\Exercises\Utilities\Farseer\Farseer Physics Engine 3.5\Common\Serialization.cs 1258 Active

    • Hello.
      Is that happening when you try to compile the file linked on the bottom of the page? If so, sorry it didn’t work for you but maybe you’ll have a better luck following all the steps in the article. You’re having two kinds of errors, missing assemblies (dll could not be found) and version/config mismatch. I show how to fix both problems in the article, starting from “If you try to run it at this point, a lot of errors will appear“. Basically for the former kind you have to manually add references to the MonoGame dlls on all projects in the solution. It’s a little tricky because you may have to remove the ones you already have that point to the wrong path (probably) and re-add them correctly. The latter kind is easier to fix since it’s just a matter of changing the configuration (in the article, starts at “If you try to run it now, you’ll get errors regarding the .NET Framework“). In my case I’ve changed all projects configurations to use the .NET 4.5, please note that again you need to do that on all projects.
      Regards

Leave a Reply