Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/Tasks/CacheGet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.Build.Framework;

#nullable disable

namespace Microsoft.Build.Tasks
{
public class CacheGet : TaskExtension
{
[Required]
public string Key { get; set; }

[Output]
public string Value { get; set; }

public override bool Execute()
{
Value = (string)BuildEngine4.GetRegisteredTaskObject(Key, RegisteredTaskObjectLifetime.Build) ?? "";
Copy link

Copilot AI Apr 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using an explicit cast may throw an exception if the retrieved object is not a string. Consider using a safe cast (e.g., 'as string') and handling the potential null result more gracefully.

Suggested change
Value = (string)BuildEngine4.GetRegisteredTaskObject(Key, RegisteredTaskObjectLifetime.Build) ?? "";
Value = BuildEngine4.GetRegisteredTaskObject(Key, RegisteredTaskObjectLifetime.Build) as string ?? "";

Copilot uses AI. Check for mistakes.
return true;
}
}
}
24 changes: 24 additions & 0 deletions src/Tasks/CacheSet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.Build.Framework;

#nullable disable

namespace Microsoft.Build.Tasks
{
public class CacheSet : TaskExtension
{
[Required]
public string Key { get; set; }

[Required]
public string Value { get; set; }

public override bool Execute()
{
BuildEngine4.RegisterTaskObject(Key, Value, RegisteredTaskObjectLifetime.Build, allowEarlyCollection: true);
return true;
}
}
}
2 changes: 2 additions & 0 deletions src/Tasks/Microsoft.Build.Tasks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@
<Compile Include="FileIO\VerifyFileHash.cs" />
<Compile Include="FileState.cs" />
<Compile Include="Copy.cs" />
<Compile Include="CacheGet.cs" />
<Compile Include="CacheSet.cs" />
<Compile Include="CreateCSharpManifestResourceName.cs" />
<Compile Include="CreateVisualBasicManifestResourceName.cs" />
<Compile Include="CreateItem.cs" />
Expand Down