diff --git a/src/Build/Logging/TerminalLogger/TerminalLogger.cs b/src/Build/Logging/TerminalLogger/TerminalLogger.cs index 44d5727c627..754165ab923 100644 --- a/src/Build/Logging/TerminalLogger/TerminalLogger.cs +++ b/src/Build/Logging/TerminalLogger/TerminalLogger.cs @@ -808,15 +808,17 @@ private void TargetFinished(object sender, TargetFinishedEventArgs e) // For cache plugin projects which result in a cache hit, ensure the output path is set // to the item spec corresponding to the GetTargetPath target upon completion. var buildEventContext = e.BuildEventContext; + var targetOutputs = e.TargetOutputs; if (_restoreContext is null && buildEventContext is not null + && targetOutputs is not null && _hasUsedCache && e.TargetName == "GetTargetPath" && _projects.TryGetValue(new ProjectContext(buildEventContext), out TerminalProjectInfo? project)) { - if (project.IsCachePluginProject) + if (project is not null && project.IsCachePluginProject) { - foreach (ITaskItem output in e.TargetOutputs) + foreach (ITaskItem output in targetOutputs) { project.OutputPath = output.ItemSpec.AsMemory(); break;