MSB4086:尝试进行数值比较

时间:2013-12-04 15:29:36

标签: msbuild

如果一个版本号大于另一个版本号,我的msbuild需要采取条件操作。 我试图像下面这样编码,但发现我得到一个错误(也在下面)。我哪里出错?

<?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 个答案:

答案 0 :(得分:2)

好的,愚蠢。

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

应该是这样的:

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

PropertyName而不是ItemName

答案 1 :(得分:0)

升级的Visual Studio为我提供了帮助。 帮助->检查更新

答案 2 :(得分:0)

更新所有NueGet软件包