Maths Class

MSBuild Extension Pack

Maths Class MSBuild Extension Pack Help 4.0.12.0
Valid TaskActions are:

Add (Required: Numbers Output: Result)

And (Required: Numbers Output: Result)

Or (Required: Numbers Output: Result)

Compare (Required: P1, P2, Comparison Output: LogicalResult)

Divide (Required: Numbers Output: Result)

Evaluate (Required: Expression Output: Result)

Multiply (Required: Numbers Output: Result)

Modulus (Required: Numbers Output: Result)

Subtract (Required: Numbers Output: Result)

LeftShift (Required: Numbers Output: Result)

RightShift (Required: Numbers Output: Result)

Remote Execution Support: NA

Inheritance Hierarchy

SystemObject  Microsoft.Build.UtilitiesTask
    MSBuild.ExtensionPackBaseTask
      MSBuild.ExtensionPack.ScienceMaths

Namespace: MSBuild.ExtensionPack.Science
Assembly: MSBuild.ExtensionPack (in MSBuild.ExtensionPack.dll) Version: 4.0.0.0

The Maths type exposes the following members.

Constructors

  NameDescription
Public methodMaths
Top
Properties

  NameDescription
Public propertyComparison
Sets the Comparison. Supports 'GreaterThan', 'LessThan', 'GreaterThanOrEquals', 'LessThanOrEquals'
Public propertyExpression
Sets the expression.
Public propertyLogicalResult
Gets the LogicalResult
Public propertyNumbers
A semicolon separated collection of numbers
Public propertyP1
Sets P1.
Public propertyP2
Sets P2.
Public propertyResult
Gets the result.
Top
Examples

<Project ToolsVersion="4.0" DefaultTargets="Default" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <TPath>$(MSBuildProjectDirectory)\..\MSBuild.ExtensionPack.tasks</TPath>
        <TPath Condition="Exists('$(MSBuildProjectDirectory)\..\..\Common\MSBuild.ExtensionPack.tasks')">$(MSBuildProjectDirectory)\..\..\Common\MSBuild.ExtensionPack.tasks</TPath>
    </PropertyGroup>
    <Import Project="$(TPath)"/>
    <Target Name="Default">
        <!-- Left Shift two numbers -->
        <MSBuild.ExtensionPack.Science.Maths TaskAction="LeftShift" Numbers="15;2">
            <Output PropertyName="RResult" TaskParameter="Result"/>
        </MSBuild.ExtensionPack.Science.Maths>
        <Message Text="LeftShift: $(RResult)"/>
        <!-- Right Shift two numbers -->
        <MSBuild.ExtensionPack.Science.Maths TaskAction="RightShift" Numbers="33;3">
            <Output PropertyName="RResult" TaskParameter="Result"/>
        </MSBuild.ExtensionPack.Science.Maths>
        <Message Text="RightShift: $(RResult)"/>
        <!-- Or two numbers -->
        <MSBuild.ExtensionPack.Science.Maths TaskAction="Or" Numbers="5;4">
            <Output PropertyName="RResult" TaskParameter="Result"/>
        </MSBuild.ExtensionPack.Science.Maths>
        <Message Text="Or: $(RResult)"/>
        <!-- Mod two numbers -->
        <MSBuild.ExtensionPack.Science.Maths TaskAction="Modulus" Numbers="10;3">
            <Output PropertyName="RResult" TaskParameter="Result"/>
        </MSBuild.ExtensionPack.Science.Maths>
        <Message Text="Modulus: $(RResult)"/>
        <!-- Evaluate a basic expression -->
        <MSBuild.ExtensionPack.Science.Maths TaskAction="Evaluate" Expression="180 / (5 * (18/3)) + 2">
            <Output PropertyName="RResult" TaskParameter="Result"/>
        </MSBuild.ExtensionPack.Science.Maths>
        <Message Text="Evaluate: $(RResult)"/>
        <!-- Add numbers -->
        <MSBuild.ExtensionPack.Science.Maths TaskAction="Add" Numbers="13;2;13;2;13;2;13;2">
            <Output PropertyName="RResult" TaskParameter="Result"/>
        </MSBuild.ExtensionPack.Science.Maths>
        <Message Text="Add: $(RResult)"/>
        <!-- Subtract numbers -->
        <MSBuild.ExtensionPack.Science.Maths TaskAction="Subtract" Numbers="13;2">
            <Output PropertyName="RResult" TaskParameter="Result"/>
        </MSBuild.ExtensionPack.Science.Maths>
        <Message Text="Subtract: $(RResult)"/>
        <!-- Divide numbers -->
        <MSBuild.ExtensionPack.Science.Maths TaskAction="Divide" Numbers="13;2.6235">
            <Output PropertyName="RResult" TaskParameter="Result"/>
        </MSBuild.ExtensionPack.Science.Maths>
        <Message Text="Divide: $(RResult)"/>
        <!-- Multiply numbers -->
        <MSBuild.ExtensionPack.Science.Maths TaskAction="Multiply" Numbers="13;2">
            <Output PropertyName="RResult" TaskParameter="Result"/>
        </MSBuild.ExtensionPack.Science.Maths>
        <Message Text="Multiply: $(RResult)"/>
        <!-- Compare whether one number is less than the other -->
        <MSBuild.ExtensionPack.Science.Maths TaskAction="Compare" P1="2" P2="60" Comparison="LessThan">
            <Output PropertyName="RResult" TaskParameter="LogicalResult"/>
        </MSBuild.ExtensionPack.Science.Maths>
        <Message Text="Compare: $(RResult)"/>
        <CallTarget Targets="Default2"/>
    </Target>
    <!-- Factorial calculation provided by Stephen Cleary -->
    <Target Name="Default2">
        <PropertyGroup>
            <Input>8</Input>
        </PropertyGroup>
        <!-- Argument error checking -->
        <MSBuild.ExtensionPack.Science.Maths TaskAction="Compare" P1="$(Input)" P2="1" Comparison="LessThan">
            <Output TaskParameter="LogicalResult" PropertyName="InputCheck"/>
        </MSBuild.ExtensionPack.Science.Maths>
        <Error Condition="'$(InputCheck)' != 'False'" Text="Input cannot be less than 1."/>
        <!-- Invoke the Factorial target with the current Input property -->
        <MSBuild Projects="$(MSBuildProjectFile)" Targets="Factorial" Properties="Input=$(Input)">
            <Output TaskParameter="TargetOutputs" ItemName="FactorialResult"/>
        </MSBuild>
        <!-- Display the result -->
        <Message Importance="high" Text="Result: @(FactorialResult)"/>
    </Target>
    <!-- The Factorial target uses FactorialCore to do the calculation, storing the result in FactorialResult -->
    <Target Name="Factorial" DependsOnTargets="FactorialCore" Outputs="$(FactorialResult)"/>
    <Target Name="FactorialCore">
        <!-- If the input is 1, then the factorial is 1 -->
        <PropertyGroup Condition="'$(Input)' == '1'">
            <FactorialResult>1</FactorialResult>
        </PropertyGroup>
        <!-- If we don't know the result yet (i.e. the input is not 1) then calculate the factorial -->
        <CallTarget Condition="'$(FactorialResult)' == ''" Targets="CalculateFactorial"/>
    </Target>
    <Target Name="CalculateFactorial">
        <!-- Subtract 1 from $(Input) -->
        <MSBuild.ExtensionPack.Science.Maths TaskAction="Subtract" Numbers="$(Input);1">
            <Output TaskParameter="Result" PropertyName="InputMinus1"/>
        </MSBuild.ExtensionPack.Science.Maths>
        <!-- Determine the factorial of $(Input) - 1 -->
        <MSBuild Projects="$(MSBuildProjectFile)" Targets="Factorial" Properties="Input=$(InputMinus1)">
            <Output TaskParameter="TargetOutputs" ItemName="SubResult"/>
        </MSBuild>
        <!-- Multiply !($(Input) - 1) by $(Input) to get the result-->
        <MSBuild.ExtensionPack.Science.Maths TaskAction="Multiply" Numbers="@(SubResult);$(Input)">
            <Output TaskParameter="Result" PropertyName="FactorialResult"/>
        </MSBuild.ExtensionPack.Science.Maths>
    </Target>
</Project>
See Also

Reference