MSB4086: A numeric comparison was attempted

Viewed 10609

My msbuild needs to take conditional action if one version number is greater than another. I've tried to code it like the following, but find I get an error (also below). Where have I gone wrong?

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
     DefaultTargets="Main"
     ToolsVersion="4.0">

  <UsingTask TaskName="CompareVersions" TaskFactory="CodeTaskFactory"     AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
    <ParameterGroup>
      <LeftHandSide Required="true"/>
      <RightHandSide Required="true"/>
      <Result ParameterType="System.Int32" Output="true"/>
    </ParameterGroup>
    <Task>
      <Code Type="Fragment" Language="cs">
        Version a = Version.Parse( LeftHandSide );
        Version b = Version.Parse( RightHandSide );
        Result = a.CompareTo(b);
      </Code>
    </Task>
  </UsingTask>

   <Target Name="Main">
    <CompareVersions LeftHandSide="3.7" RightHandSide="3.6">
      <Output ItemName="ComparisonResult" TaskParameter="Result"/>
    </CompareVersions>
    <Message Text="ComparisonResult=$(ComparisonResult)"></Message>
    <PropertyGroup>
      <Setting Condition="$(ComparisonResult) &lt; 0">true</Setting>
    </PropertyGroup>
    <Message Text="Setting=$(Setting)"></Message>
   </Target>

</Project>

S:\>msbuild test.proj Microsoft (R) Build Engine version
4.0.30319.18408 [Microsoft .NET Framework, version 4.0.30319.18408] Copyright (C) Microsoft Corporation. All rights reserved.

Build started 04/12/2013 15:26:38.
Project "S:\test.proj" on node 1 (default targets).
Main:
   ComparisonResult=
S:\test.proj(28,16): error MSB4086: A numeric comparison was attempted on "$(ComparisonResult)" that evaluates to "" instead of a number, in conditio n "$(ComparisonResult) < 0".
Done Building Project "S:\test.proj" (default targets) -- FAILED.


Build FAILED.

"S:\test.proj" (default target) (1) ->
(Main target) ->
S:\test.proj(28,16): error MSB4086: A numeric comparison was attempted on "$(ComparisonResult)" that evaluates to "" instead of a number, in condit ion "$(ComparisonResult) < 0".

   0 Warning(s)
   1 Error(s)

Time Elapsed 00:00:00.09

S:\>
3 Answers

Ok, daftness.

<CompareVersions LeftHandSide="3.7" RightHandSide="3.6">
  <Output ItemName="ComparisonResult" TaskParameter="Result"/>
</CompareVersions>

should be this:

<CompareVersions LeftHandSide="3.7" RightHandSide="3.6">
  <Output PropertyName="ComparisonResult" TaskParameter="Result"/>
</CompareVersions>

PropertyName instead of ItemName

Upgrade visual studio helped for me. Help -> Check for Updates

Maybe the reason was that it's upgraded also some .Net packages.

Related