dotnet / dotnet/msbuild

Collection Expression like condition syntax (with `in` / `not in` csharp-y idioms)

Open
#12,218 3 comments 0 reactions 0 assignees View on GitHub
Area: Language backlog needs-design triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 8h
Merged PRs (30d)
141

Description

### Summary

Introduce support for collection-based condition expressions in MSBuild, such as `$(TargetOS) not in ['browser', 'haiku', 'illumos']`, to simplify and clarify multi-value comparisons.

### Background and Motivation

MSBuild currently requires verbose chaining of `and`/`or` conditions to check if a property matches (or doesn't match) a set of values. This becomes unwieldy and error-prone, especially in cross-platform builds or SDK logic where exclusion lists are common.

Example today:

```xml
Condition="'$(TargetOS)' != 'browser' and '$(TargetOS)' != 'haiku' and '$(TargetOS)' != 'illumos' and '$(TargetOS)' != 'netbsd' and '$(TargetOS)' != 'solaris'"
```
This is hard to read, maintain, and scale.

There are several cases in the runtime repo (e.g., [this one](https://github.com/dotnet/runtime/pull/117953#discussion_r2226086592)) where this change can significantly reduce code length.

### Proposed Feature

Enable syntax like:
```xml
Condition="'$(TargetOS)' not in ['browser', 'haiku', 'illumos', 'netbsd', 'solaris']"
```

or:
```xml
Condition="!['browser', 'haiku', 'illumos', 'netbsd', 'solaris'].Contains('$(TargetOS)')"
```

This would improve clarity and reduce duplication in build logic.

### Alternative Designs

Allow item groups in conditions with .Contains():

```xml

<_NativeAotSupportedOS Condition="!@(UnsupportedOS->'%(Identity)').Contains('$(TargetOS)')">true

```

This works but is verbose and not usable inline in many contexts.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.