Document whether tasks can cache TaskItems
- Dominant language
- C#
- Stars
- 5.5k
- Forks
- 1.5k
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 133
Description
A task can safely cache `TaskItem`s as far as I can tell. We should document that.
I validated with code like this: [task-with-cached-TaskItem.zip](https://github.com/dotnet/msbuild/files/6976747/task-with-cached-TaskItem.zip)
A task that trivially caches a `TaskItem` object:
```c#
public class Class1 : Task
{
private static TaskItem item = new("itemSpec",
new Dictionary() {
["MetaA"] = "valueA"
});
[Output]
public TaskItem OutParam { get; private set; }
public override bool Execute()
{
OutParam = item;
return true;
}
}
```
A project that calls it twice and modifies the output of the first time:
```xml
```
This produces
```sh-session
❯ dotnet build .\XMLFile1.csproj
Microsoft (R) Build Engine version 17.0.0-preview-21409-06+682bfcaf3 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
First O: itemSpec, a: valueA b:
Changed O: itemSpec, a: valueA b: b
Last O: itemSpec, a: valueA b: b
O2: itemSpec, a: valueA b:
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:00.10
```
So the mutated object logged as "Changed O" must be a distinct object from the one in the static.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.