dotnet / dotnet/msbuild

Add an MSBuild Property Function to check if a property actually exists (vs relying on coercion to empty string)

Open
#12,404 5 comments 5 reactions 2 assignees Claimed by @baronfel View on GitHub
Area: Engine
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 8h
Merged PRs (30d)
141

Description

### Summary

Today it's difficult to detect in MSBuild logic if a given property is present-with-an-empty-value vs completely undefined. This makes it difficult to encode coalescing logic where a present-but-empty property is intended to overwrite another property's value entirely.

### Background and Motivation

We should have an MSBuild Condition function, something like `PropertyExists('PropertyName')`, that would return a boolean if the Property existed on the Project in any way - including an empty value.

Then we could more easily write conditions like:

```xml

<_UserSpecifiedToolPackageRids Condition="PropertyExists('ToolPackageRuntimeIdentifiers')">$(ToolPackageRuntimeIdentifiers)
<_UserSpecifiedToolPackageRids Condition="!PropertyExists('ToolPackageRuntimeIdentifiers')">$(RuntimeIdentifiers)

```

### Proposed Feature

We should have an MSBuild Condition function, something like `PropertyExists('PropertyName')`, that would return a boolean if the Property existed on the Project in any way - including an empty value.

### Alternative Designs

_No response_

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.