Skip to content

Commit 2965ffe

Browse files
committed
add CacheGet and CacheSet tasks
1 parent 7500f06 commit 2965ffe

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

src/Tasks/CacheGet.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using Microsoft.Build.Framework;
5+
6+
#nullable disable
7+
8+
namespace Microsoft.Build.Tasks
9+
{
10+
public class CacheGet : TaskExtension
11+
{
12+
[Required]
13+
public string Key { get; set; }
14+
15+
[Output]
16+
public string Value { get; set; }
17+
18+
public override bool Execute()
19+
{
20+
Value = (string)BuildEngine4.GetRegisteredTaskObject(Key, RegisteredTaskObjectLifetime.Build) ?? "";
21+
return true;
22+
}
23+
}
24+
}

src/Tasks/CacheSet.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using Microsoft.Build.Framework;
5+
6+
#nullable disable
7+
8+
namespace Microsoft.Build.Tasks
9+
{
10+
public class CacheSet : TaskExtension
11+
{
12+
[Required]
13+
public string Key { get; set; }
14+
15+
[Required]
16+
public string Value { get; set; }
17+
18+
public override bool Execute()
19+
{
20+
BuildEngine4.RegisterTaskObject(Key, Value, RegisteredTaskObjectLifetime.Build, allowEarlyCollection: true);
21+
return true;
22+
}
23+
}
24+
}

src/Tasks/Microsoft.Build.Tasks.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@
204204
<Compile Include="FileIO\VerifyFileHash.cs" />
205205
<Compile Include="FileState.cs" />
206206
<Compile Include="Copy.cs" />
207+
<Compile Include="CacheGet.cs" />
208+
<Compile Include="CacheSet.cs" />
207209
<Compile Include="CreateCSharpManifestResourceName.cs" />
208210
<Compile Include="CreateVisualBasicManifestResourceName.cs" />
209211
<Compile Include="CreateItem.cs" />

0 commit comments

Comments
 (0)