Custom task [Output] property behavior when not set explicitly is confusing
- Dominant language
- C#
- Stars
- 5.5k
- Forks
- 1.5k
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 141
Description
Hello there,
I ran into a custom task property's [Output] attribute behavior which I did not expect, and which I find somewhat confusing. Also, I didn't find it documented nor discussed anywhere so here I am.
In a nutshell, if I have a custom task with a property attributed with [Output], and I don't set the value of the property in the task, MSBuild property assigned to given task property retains its previous value:
```
a;b;c
...
```
yields
```
Test:
Ids: a;b;c
Ids (after no set): a;b;c
```
Granted, _not setting_ output property value is somewhere between being unlikely and being a bug. But now that I ran into it I guess I'm spoiled by C#'s ```out``` behavior so I would expect _not setting_ would amount to target MSBuild property ending up empty. Moreover, a straightforward would-be fix
```
else
{
Identifiers = null;
}
```
is not enough, one needs
```
else
{
Identifiers = string.Empty;
}
```
to end up with what I thought I would end up with:
```
Ids: a;b;c
Ids (after no set):
```
Feels like a small trap one can fall into unexpectedly, which perhaps could be avoided by either clarifying design intent/documentation on the matter, or by cleaning property values.
Cheers,
L.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.