Condition with regex

Add properties for all XToolkit projects that do not contain “Tests” in the name:

    Condition="$([System.Text.RegularExpressions.Regex]::IsMatch($(ProjectName), '^XToolkit.(.*)(?&lt;!Tests)$'))">
    <!-- Your properties to add -->


XToolkit.ProjectA - add
XToolkit.ProjectA.SubProjectA - ok
XToolkit.ProjectA.Tests - ignore
XToolkit.ProjectB - add
XToolkit.Tests - ignore

Condition debug

  • Add new target to project:
<Target Name="MyTarget">
        Condition="...your condition..."
        Text="Applied to project: $(ProjectName)"
        Importance="High" />
  • Run target:
msbuild ExampleProject.csproj /t:MyTarget

Теги: msbuild, regex