Rules Engine for .NET

NRules is an open source rules engine for .NET that is based on the Rete matching algorithm. Rules are authored in C# using internal DSL.

NRules is also an inference engine, where, unlike with scripting engines, there is no predefined order in which rules are executed. Instead, inference engine figures out which rules should be activated based on the facts given to it, and then executes them according to a conflict resolution algorithm. Among other features, NRules supports forward chaining, complex fact queries, negative, existential and universal quantifiers.

To learn more, go to the corresponding sections of the NRules documentation.

Getting Started

To install NRules, get the package from nuget

> dotnet add package NRules

Use the following resources to get up and running with NRules

Getting Help

Use the following discussion and Q&A platforms to get help with NRules

Getting the Right Package

Choose the right package from the NRules suite, depending on your needs and the project structure

Name Nuget Overview Documentation
NRules NuGet Meta package that installs the canonical rules model, fluent DSL and the engine runtime. Reference this package from the projects that don't separate rules from the application code. Guide
NRules.Runtime NuGet Rules engine runtime. Reference this package from the projects that compile and execute rules. API
NRules.Fluent NuGet Fluent DSL for NRules. Reference this package from the projects that contain rules. API
NRules.RuleModel NuGet Canonical rules model. Reference this package from the projects that deal with the intermediate rules representation. This package is transitively referenced by most other NRules packages. API
NRules.Json NuGet Rules serialization to and from JSON. Reference this package from the projects that handle rules serialization. Guide API
NRules.Testing NuGet Rules unit testing and expectations assertion. Reference this package from the projects that implement rules unit tests. Guide API

Building from Source

To build NRules from the source code, clone the repo from GitHub, make sure PowerShell is installed, then run the build script

> .\build.bat [Target] [Component]

Default target is Build.

Default component is Core. Use the following components to build other parts of the engine

  • All - build everything
  • Core - build the rules engine, NRules.Testing and NRules.Json
  • Visualizer - build debugger visualizer (Windows only)
  • Integration - build integration libraries
  • Samples - build samples
  • Benchmark - build performance benchmarks
  • Documentation - build documentation

Built artifacts are found under the build folder.

Contributing

Clone NRules on GitHub.

See Contributor Guide for the guidelines on how to contribute to the project.