SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

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

Last post 11-21-2016 6:56 AM by sbridewell. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 11-12-2016 6:56 PM

    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

    ICSharpCode.SharpDevelop.Project.ProjectLoadException: A numeric comparison was attempted on "$(TargetPlatformMinVersion)" that evaluates to "10.0.10586.0" instead of a number, in condition "'$(TargetPlatformIdentifier)' == 'UAP' And '$(TargetPlatformMinVersion)' != '' And '$(TargetPlatformMinVersion)' > '10.0.10587.0'".  C:\Program Files (x86)\MSBuild\Microsoft\WindowsXaml\v14.0\Microsoft.Windows.UI.Xaml.Common.targets ---> Microsoft.Build.Exceptions.InvalidProjectFileException: A numeric comparison was attempted on "$(TargetPlatformMinVersion)" that evaluates to "10.0.10586.0" instead of a number, in condition "'$(TargetPlatformIdentifier)' == 'UAP' And '$(TargetPlatformMinVersion)' != '' And '$(TargetPlatformMinVersion)' > '10.0.10587.0'".  C:\Program Files (x86)\MSBuild\Microsoft\WindowsXaml\v14.0\Microsoft.Windows.UI.Xaml.Common.targets
       at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, Object[ args)
       at Microsoft.Build.Evaluation.NumericComparisonExpressionNode.BoolEvaluate(IConditionEvaluationState state)
       at Microsoft.Build.Evaluation.AndExpressionNode.BoolEvaluate(IConditionEvaluationState state)
       at Microsoft.Build.Evaluation.GenericExpressionNode.Evaluate(IConditionEvaluationState state)
       at Microsoft.Build.Evaluation.ConditionEvaluator.EvaluateConditionCollectingConditionedProperties[P,I](String condition, ParserOptions options, Expander`2 expander, ExpanderOptions expanderOptions, Dictionary`2 conditionedPropertiesTable, String evaluationDirectory, ElementLocation elementLocation, ILoggingService loggingServices, BuildEventContext buildEventContext)
       at Microsoft.Build.Evaluation.Evaluator`4.EvaluateConditionCollectingConditionedProperties(ProjectElement element, ExpanderOptions expanderOptions, ParserOptions parserOptions)
       at Microsoft.Build.Evaluation.Evaluator`4.EvaluatePropertyGroupElement(ProjectPropertyGroupElement propertyGroupElement)
       at Microsoft.Build.Evaluation.Evaluator`4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport)
       at Microsoft.Build.Evaluation.Evaluator`4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement)
       at Microsoft.Build.Evaluation.Evaluator`4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport)
       at Microsoft.Build.Evaluation.Evaluator`4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement)
       at Microsoft.Build.Evaluation.Evaluator`4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport)
       at Microsoft.Build.Evaluation.Evaluator`4.Evaluate()
       at Microsoft.Build.Evaluation.Evaluator`4.Evaluate(IEvaluatorData`4 data, ProjectRootElement root, ProjectLoadSettings loadSettings, Int32 maxNodeCount, PropertyDictionary`1 environmentProperties, ILoggingService loggingService, IItemFactory`2 itemFactory, IToolsetProvider toolsetProvider, ProjectRootElementCache projectRootElementCache, BuildEventContext buildEventContext, ProjectInstance projectInstanceIfAnyForDebuggerOnly)
       at Microsoft.Build.Evaluation.Project.ReevaluateIfNecessary(ILoggingService loggingServiceForEvaluation)
       at Microsoft.Build.Evaluation.Project.Initialize(IDictionary`2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectLoadSettings loadSettings)
       at Microsoft.Build.Evaluation.Project..ctor(ProjectRootElement xml, IDictionary`2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectCollection projectCollection, ProjectLoadSettings loadSettings)
       at ICSharpCode.SharpDevelop.Project.MSBuildInternals.LoadProject(ProjectCollection projectCollection, ProjectRootElement rootElement, IDictionary`2 globalProps)
       at ICSharpCode.SharpDevelop.Project.MSBuildBasedProject.OpenConfiguration(String configuration, String platform)
       at ICSharpCode.SharpDevelop.Project.MSBuildBasedProject.GetEvaluatedProperty(String propertyName)
       at ICSharpCode.SharpDevelop.Project.MSBuildBasedProject.LoadProjectInternal(ProjectLoadInformation loadInformation)
       at ICSharpCode.SharpDevelop.Project.MSBuildBasedProject..ctor(ProjectLoadInformation loadInformation)
       --- End of inner exception stack trace ---
       at ICSharpCode.SharpDevelop.Project.MSBuildBasedProject..ctor(ProjectLoadInformation loadInformation)
       at ICSharpCode.SharpDevelop.Project.CompilableProject..ctor(ProjectLoadInformation information)
       at CSharpBinding.CSharpProject..ctor(ProjectLoadInformation loadInformation)
       at CSharpBinding.CSharpProjectBinding.LoadProject(ProjectLoadInformation loadInformation)
       at ICSharpCode.SharpDevelop.Project.SDProjectService.LoadProject(ProjectLoadInformation info)
       at ICSharpCode.SharpDevelop.Project.SolutionLoader.LoadProjectWithErrorHandling(ProjectLoadInformation projectInfo)

    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

    call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat"

    to the pre-build commands, seemingly enforcing the use of MSBuild 14.0 at all stages. Can I do something similar within SharpDevelop to tell it to use MSBuild 14.0 to load these projects?

    Thanks

    Simon

     

    My SharpDevelop info:

    SharpDevelop Version : 5.1.0.5134-RC-d5052dc5
    .NET Version         : 4.6.01586
    OS Version           : Microsoft Windows NT 6.3.9600.0
    Current culture      : English (United Kingdom) (en-GB)
    Running under WOW6432, processor architecture: x86-64
    Working Set Memory   : 410216kb
    GC Heap Memory       : 231786kb

     

    Filed under: ,
  • 11-13-2016 6:19 PM In reply to

    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:

     

    C:\Program Files (x86)\MSBuild\Microsoft\WindowsXaml\v14.0\Microsoft.Windows.UI.Xaml.Common.targets(6,18) : Error MSB4086: A numeric comparison was attempted on "$(TargetPlatformMinVersion)" that evaluates to "10.0.10586.0" instead of a number, in condition "'$(TargetPlatformIdentifier)' == 'UAP' And '$(TargetPlatformMinVersion)' != '' And '$(TargetPlatformMinVersion)' > '10.0.10587.0'".

     

    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 :-)

     

    Thanks

     

    Simon

     

     

  • 11-21-2016 6:56 AM In reply to

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

    I think I may have cracked it.

    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:

    public static readonly BuildWorkerManager MSBuild140 = new BuildWorkerManager("ICSharpCode.SharpDevelop.BuildWorker140.exe");

    And in the RunBuildAsync method I added some lines near the end:

                } else {
                    if (DotnetDetection.IsBuildTools2015Installed()) {
                        BuildWorkerManager.MSBuild140.RunBuildJob(job, loggerChain, OnDone, cancellationToken);
                    }
                    else
    if (DotnetDetection.IsBuildTools2013Installed()) {
                        BuildWorkerManager.MSBuild120.RunBuildJob(job, loggerChain, OnDone, cancellationToken);
                    } else {
                        BuildWorkerManager.MSBuild40.RunBuildJob(job, loggerChain, OnDone, cancellationToken);
                    }
                }
                return tcs.Task;

    And I added a method to DotnetDetection.cs in the ICSharpCode.SharpDevelop project:

            /// <summary>
            /// Gets whether the Microsoft Build Tools 2015 (MSBuild 14.0) is installed.
            /// </summary>
            public static bool IsBuildTools2015Installed()
            {
                // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\DevDiv\BuildTools\Servicing\14.0
                using (var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\DevDiv\BuildTools\Servicing\14.0\MSBuild")) {
                    return key != null && key.GetValue("Install") as int? >= 1;
                }
            }

    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:

    Normal 0 false false false EN-GB X-NONE X-NONE /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin-top:0cm; mso-para-margin-right:0cm; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0cm; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi; mso-fareast-language:EN-US;} C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(1697,5) : Warning MSB3276: Found conflicts between different versions of the same dependent assembly. Please set the "AutoGenerateBindingRedirects" property to true in the project file. For more information, see http://go.microsoft.com/fwlink/?LinkId=294190.

    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.

Page 1 of 1 (3 items)
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.