IBM Support

Technote (FAQ)


How to integrate MsBuild task of IBM WebSphere ILOG Rules for .NET in your own code?


In order to fully automate deployment it may be necessary to call those tasks from your code and be able to react to their outcomes.


MSBuild relies on some Assemblies, those can be referenced as:

- using ILOG.Rules.ExecutionServer.MSBuildTask;

- using Microsoft.Build.Utilities;

- using Microsoft.Build.BuildEngine;

- using Microsoft.Build.Framework;

The Rules for .Net specific assembly is :

<ILOG Rules for .NET_installDir>\Rule Execution Server for .NET\Bin\Public Assemblies\ILOG.Rules.ExecutionServer.MSBuildTask.dll

Refer to the Class Library for details on the APIs.

Here is a sample code snippet to create a ruleApp (deployable to a Rule Execution Server) from a .brc file (that you would get either from Rule Team Server or Visual Studio ) :

We first create a RuleApp MSBuild task (ILOG.Rules.ExecutionServer.MSBuildTask.CreateRuleApp) , then set a logger to retrieve/handle output log and messages, then set the different parameters (brc file, names and versions of the new RuleApp and Ruleset , finally we also set the output zip file name that can be deployed to the Rule Execution Server (RES) through another MSBuild task or the RES console ) :

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using ILOG.Rules.ExecutionServer.MSBuildTask;

using Microsoft.Build.Utilities;

using Microsoft.Build.BuildEngine;

using Microsoft.Build.Framework;

namespace ConsoleRuleApp


    class Program


       // Constant names used in this task

       const string RULESET_BRCFILE = "brcfile";

       const string RULESET_DESCRIPTION = "description";

       const string RULESET_DISPLAYNAME = "displayname";

       const string RULESET_ITEM = "ruleset";

       const string RULESET_NAME = "name";

       const string RULESET_STATUS = "status";

       const string RULESET_VERSION = "version";

       static void Main(string[] args)


           ILOG.Rules.ExecutionServer.MSBuildTask.CreateRuleApp task = new CreateRuleApp();

           task.BuildEngine = new LoggerBuildEngine();

           task.Name = "ruleAppName";

           task.Destfile = "";

           task.Version = "1.0";

           task.Displayname = "My Display Name";

           task.Description = "My Description";

           TaskItem item = new TaskItem();

           item.SetMetadata(RULESET_NAME, "Ruleset");

           item.SetMetadata(RULESET_VERSION, "1.0");

           item.SetMetadata(RULESET_DISPLAYNAME, "Display RS");

           item.SetMetadata(RULESET_DESCRIPTION, "Description RS");

            //the input file path

           item.SetMetadata(RULESET_BRCFILE, "BusinessRules.brc");

           task.Ruleset = new TaskItem[1] { item };




        // Logger Utility

        public class LoggerBuildEngine : IBuildEngine {

        public List<BuildErrorEventArgs> LogErrorEvents =  new List<BuildErrorEventArgs>();

        public List<BuildMessageEventArgs> LogMessageEvents = new List<BuildMessageEventArgs>();

        public List<CustomBuildEventArgs> LogCustomEvents = new List<CustomBuildEventArgs>();

        public List<BuildWarningEventArgs> LogWarningEvents =  new List<BuildWarningEventArgs>();


        public int ColumnNumberOfTaskNode {           get { return 0; }        }

        public bool ContinueOnError{   get {throw new NotImplementedException();} }

        public int LineNumberOfTaskNode { get { return 0; } }

        public string ProjectFileOfTaskNode

{ get { return "fake ProjectFileOfTaskNode"; } }

        public void LogCustomEvent(CustomBuildEventArgs e)

{  LogCustomEvents.Add(e);  }

        public void LogErrorEvent(BuildErrorEventArgs e)        

{LogErrorEvents.Add(e);  }

        public void LogMessageEvent(BuildMessageEventArgs e)

{ LogMessageEvents.Add(e);  }


        public void LogWarningEvent(BuildWarningEventArgs e)    

{ LogWarningEvents.Add(e); }

        public bool BuildProjectFile(string projectFileName, string[] targetNames,                                                        System.Collections.IDictionary globalProperties,                                                         System.Collections.IDictionary targetOutputs)                                                            {

     throw new NotImplementedException();




Document information

More support for: WebSphere ILOG Rules for .NET

Software version: 7.0.1, 7.0.2, 7.0.3, 7.1, 7.1.1,,

Operating system(s): Windows

Reference #: 1496945

Modified date: 2012-03-14