Skip to content
Merged
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
6 changes: 2 additions & 4 deletions src/Build/Instance/TaskRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -950,18 +950,16 @@ private static bool IdentityParametersMatch(in TaskHostParameters x, in TaskHost
return false;
}

// For exact match, all properties must be equal (case-insensitive)
// For exact match, only identity properties must be equal
// Paths are NOT part of identity - they're just resolved locations
return string.Equals(x.Runtime, y.Runtime, StringComparison.OrdinalIgnoreCase) &&
string.Equals(x.Architecture, y.Architecture, StringComparison.OrdinalIgnoreCase) &&
string.Equals(x.DotnetHostPath, y.DotnetHostPath, StringComparison.OrdinalIgnoreCase) &&
string.Equals(x.MSBuildAssemblyPath, y.MSBuildAssemblyPath, StringComparison.OrdinalIgnoreCase) &&
x.TaskHostFactoryExplicitlyRequested == y.TaskHostFactoryExplicitlyRequested;
}
else
{
// Fuzzy match: null is treated as "don't care"
// Only check runtime and architecture for fuzzy matching

string runtimeX = x.Runtime;
string runtimeY = y.Runtime;
string architectureX = x.Architecture;
Expand Down
28 changes: 26 additions & 2 deletions src/Framework/TaskHostParameters.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;

namespace Microsoft.Build.Framework
{
/// <summary>
/// A readonly struct that represents task host parameters used to determine which host process to launch.
/// </summary>
public readonly struct TaskHostParameters
public readonly struct TaskHostParameters : IEquatable<TaskHostParameters>
{
/// <summary>
/// A static empty instance to avoid allocations when default parameters are needed.
Expand Down Expand Up @@ -72,6 +73,29 @@ internal TaskHostParameters(
/// </summary>
public bool? TaskHostFactoryExplicitlyRequested => _taskHostFactoryExplicitlyRequested;

public override bool Equals(object? obj) => obj is TaskHostParameters other && Equals(other);

public bool Equals(TaskHostParameters other) =>
StringComparer.OrdinalIgnoreCase.Equals(Runtime ?? string.Empty, other.Runtime ?? string.Empty)
&& StringComparer.OrdinalIgnoreCase.Equals(Architecture ?? string.Empty, other.Architecture ?? string.Empty)
&& TaskHostFactoryExplicitlyRequested == other.TaskHostFactoryExplicitlyRequested;

public override int GetHashCode()
{
// Manual hash code implementation for compatibility with .NET Framework 4.7.2
var comparer = StringComparer.OrdinalIgnoreCase;

unchecked
{
int hash = 17;
hash = hash * 31 + comparer.GetHashCode(Runtime ?? string.Empty);
hash = hash * 31 + comparer.GetHashCode(Architecture ?? string.Empty);
hash = hash * 31 + (TaskHostFactoryExplicitlyRequested?.GetHashCode() ?? 0);

return hash;
}
}

/// <summary>
/// Gets a value indicating whether returns true if parameters were unset.
/// </summary>
Expand Down Expand Up @@ -134,7 +158,7 @@ internal TaskHostParameters WithTaskHostFactoryExplicitlyRequested(bool taskHost
/// <summary>
/// The method was added to sustain compatibility with ITaskFactory2 factoryIdentityParameters parameters dictionary.
/// </summary>
internal Dictionary<string, string> ToDictionary() => new(3)
internal Dictionary<string, string> ToDictionary() => new(3, StringComparer.OrdinalIgnoreCase)
{
{ nameof(Runtime), Runtime ?? string.Empty },
{ nameof(Architecture), Architecture ?? string.Empty },
Expand Down