Using SharpDevelop with Xamarin.Forms Windows projects - A numeric comparison was attempted...

Hello, I'm trying to use SharpDevelop with Xamarin.Forms projects which were created using Visual Studio 2015 community edition. Android projects seem to be working OK so far, and I know I can't build iOS projects because I don't have a Mac, but SharpDevelop seems to be unable to load projects for Windows 10 Universal (.UWP.csproj), Windows 8 Desktop (.Windows.csproj) or Windows 8 Phone (.WinPhone.csproj). Instead, an error is displayed similar to

The problem appears to be that MSBuild is trying to compare a 4-part version number with a property which MSBuild is expecting to be numeric, and that MSBuild 14.0 allows this but MSBuild 12.0 doesn't. I've tried resolving this by changing any references to VisualStudioVersion or ToolsVersion in the project files from 12 or 12.0 to 14 or 14.0, but it just seems to move the problem to a similar error another condition somewhere else in the MSBuild target files, each time saying a numeric comparison was attempted with a 4-part version number, and it seems that for some reason it's MSBuild 12.0 attempting the comparison, even though I'm trying to use MSBuild 14.0.

If I use MSBuild Explorer to build the project, this particular problem seems to go away if I add the line

Re: Using SharpDevelop with Xamarin.Forms Windows projects - A numeric comparison was attempted...

Today I downloaded the source for SharpDevelop 5.1.0.5216 to look at how it references MSBuild assemblies, and found that the main project references version 4.0 (not version 12.0 as I previously thought) of Microsoft.Build and Microsoft.Build.Framework, both from C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\, which according to this bug report is a "stale" version distributed with the .net framework, and which is only still there because removing it would be a breaking change.

I removed those 2 references from the SharpDevelop project and replaced them with references to the corresponding assemblies from C:\Program Files (x86)\Reference
Assemblies\Microsoft\MSBuild\v14.0 (apparently this is distributed with either Visual Studio 2015 or Microsoft Build Tools 2015). As expected, building this gave me a warning, because other projects in the solution will still be referencing version 4.0 of these assemblies.

MSB3276: Found conflicts between different versions of the same dependent
assembly. Please set the “AutoGenerateBindingRedirects” property to true in the
project file

Rather than going through each project individually to identify and update any references to Microsoft.Build* assemblies (which would probably be the proper thing to do), I tried adding a property to the SharpDevelop.csproj file:

<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>

I reloaded the solution when prompted, and saw some messages in the output window (although they don't appear in the errors and warnings window:

The primary reference "Microsoft.Build" could not be resolved because it has a higher version "14.0.0.0" than exists in the current target framework. The version found in the current target framework is "4.0.0.0".
The primary reference "Microsoft.Build.Framework" could not be resolved because it has a higher version "14.0.0.0" than exists in the current target framework. The version found in the current target framework is "4.0.0.0".
The primary reference "Microsoft.Build, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" could not be resolved because it has a higher version "12.0.0.0" than exists in the current target framework. The version found in the current target framework is "4.0.0.0".
The primary reference "Microsoft.Build.Framework, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" could not be resolved because it has a higher version "12.0.0.0" than exists in the current target framework. The version found in the current target framework is "4.0.0.0".

The solution builds OK, there are some warnings but none of them seem to be about references to Microsoft.Build* assemblies, so I try running the SharpDevelop.exe I've just built, and loading the solution containing my Xamarin.Forms projects. This time the projects load without an error, however I now get a similar error about a numeric comparison being attempted, but when trying to build the projects rather than when trying to load them:

I notice this time the error appears to be thrown in version 14.0 of something (presumably MSBuild), rather than version 12.0, which is where all the errors were when building using MSBuild Explorer. I'm even more confused now, as 14.0 is the version I want to use to build the project.

I've never before dug this deep into the myriad files which make up the MSBuild processes that I normally take for granted when I hit the Build button, so I could be barking up completely the wrong tree. Any advice on whether I'm going about this all wrong (or that I'm trying something which just can't be done in SharpDevelop 5.1 without rewriting large chunks of it) would be greatly appreciated :-)

Re: Using SharpDevelop with Xamarin.Forms Windows projects - A numeric comparison was attempted...

First, I took a copy of the existing ICSharpCode.SharpDevelop.BuildWorker120 project, renamed it to ICSharpCode.SharpDevelop.BuildWorker140, added it into the SharpDevelop solution and changed the 120 in its assembly name and default namespace to 140. I removed the references in this project to Microsoft.Build and Microsoft.Build.Framework and replaced them with version 14.0.0.0 of the same assemblies from the GAC.

I also replaced references to Microsoft.Build, Microsoft.Build.Framework and Microsoft.Build.Engine with version 14.0.0.0 of the same assemblies from the GAC in the following projects: SharpDevelop, CodeAnalysis, CppBinding, CSharpBinding, FSharpBinding, VBBinding, WixBinding, PackageManagement, ICSharpCode.Build.Tasks and ICSharpCode.SharpDevelop (but not the ICSharpCode.SharpDevelop.BuildWorker* projects).

In the SharpDevelop project, in BuildWorkerManager.cs, I added a new field:

There may be a bit more to it than this, for example the MSBuildBasedProject constructor appears to be checking whether MSBuild tools 2013 is installed and it might be a good idea to perform the same check for version 2015, but I haven't implemented that.

The resulting solution builds, albeit with the following warning, apparently in the SharpDevelop project:

Running the SharpDevelop I'd just built, I was able to load my Xamarin solution. On building it, I found that it was attempting to use the platform "AnyCPU" to build the UWP and iOS projects, when that platform wasn't defined in those project files, so I used the configuration editor to change the platform setting to x86 (for UWP) and iPhoneSimulator (for iOS) for those projects, and they all seem to build OK.

The only projects which won't load now are two .shproj files, for example this one. Unlike the other projects, which are more or less standard .csproj files, this appears to be a brand new project type intended to contain class files to be shared between UWP, Windows and WinPhone Xamarin projects, and to load them I think we'd need a new language bindings project, so that's well outside the scope of my original question.