本文介绍了MSB4086:试图进行数字比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

好,笨拙.

<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

PropertyName instead of ItemName

这篇关于MSB4086:试图进行数字比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 22:32