Skip to content

SelectiveConditionEvaluator is a library build on top of msBuild. It allows to evaluate conditions (from csproj attribute for example) in selective way, taking into consideration only given properties.

License

Notifications You must be signed in to change notification settings

bulatgrzegorz/selective-condition-evaluator

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SelectiveConditionEvaluator

SelectiveConditionEvaluator is a library build on top of msBuild. It allows to evaluate conditions (from csproj attribute for example) in selective way, taking into consideration only given properties.

Installing

SelectiveConditionEvaluator is available on nuget, you can install it simple by executing:

dotnet add package SelectiveConditionEvaluator

Usage

Library is exposing SelectiveParser class. You can initialize it, executing constructor with property/properties of choice:

var parser = new SelectiveConditionEvaluator.SelectiveParser("TargetFramework", "netstandard1.6"); 

then, you can simply evaluate any condition, while only given property will be included into logic:

var result = parser.EvaluateSelective("'$(TargetFramework)' == 'netstandard1.6'"); //true

Internals

As parser is build on top of msBuild, it will deal with everything that would be normally accepted:

var parser = new SelectiveConditionEvaluator.SelectiveParser("TargetFramework", "net45");
var result = parser.EvaluateSelective("'$(TargetFramework.TrimEnd(`0123456789`))' == 'net'"); //true
var result = parser.EvaluateSelective("('$(TargetFramework)' == 'net7.0' and '$(OS)' == 'Windows_NT') or ('$(TargetFramework)' == 'net45' and '$(OS)' == 'Ubuntu')"); //true

as example above, condition can contain any other properties that are not given. Condition will still be evaluated correctly in context of properties of interest.

About

SelectiveConditionEvaluator is a library build on top of msBuild. It allows to evaluate conditions (from csproj attribute for example) in selective way, taking into consideration only given properties.

Resources

License

Stars

Watchers

Forks

Languages

  • C# 100.0%