Skip to content
Closed
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
22 changes: 22 additions & 0 deletions src/Build.UnitTests/Evaluation/Expander_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1991,6 +1991,28 @@ public void TestGetPathToReferenceAssembliesAsFunction()
log.AssertLogDoesntContain("Reference assembly paths do not match");
}

/// <summary>
/// Test that ToolLocationHelper fast-path methods work correctly
/// </summary>
[Fact]
public void TestToolLocationHelperFastPaths()
{
PropertyDictionary<ProjectPropertyInstance> pg = new PropertyDictionary<ProjectPropertyInstance>();

Expander<ProjectPropertyInstance, ProjectItemInstance> expander = new Expander<ProjectPropertyInstance, ProjectItemInstance>(pg, FileSystems.Default);

// Test GetPlatformSDKLocation with fast-path
string result1 = expander.ExpandIntoStringLeaveEscaped("$([Microsoft.Build.Utilities.ToolLocationHelper]::GetPlatformSDKLocation('Windows', '10.0'))", ExpanderOptions.ExpandProperties, MockElementLocation.Instance);

// Test GetPlatformSDKDisplayName with fast-path
string result2 = expander.ExpandIntoStringLeaveEscaped("$([Microsoft.Build.Utilities.ToolLocationHelper]::GetPlatformSDKDisplayName('Windows', '10.0'))", ExpanderOptions.ExpandProperties, MockElementLocation.Instance);

// The results should be non-null strings (actual values depend on system configuration)
// We're mainly testing that the methods execute without errors through the fast-path
Assert.True(result1 != null, "GetPlatformSDKLocation should not return null");
Assert.True(result2 != null, "GetPlatformSDKDisplayName should not return null");
}

/// <summary>
/// Expand property function that takes a null argument
/// </summary>
Expand Down
20 changes: 20 additions & 0 deletions src/Build/Evaluation/Expander/WellKnownFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.Build.Framework;
using Microsoft.Build.Shared;
using Microsoft.Build.Shared.FileSystem;
using Microsoft.Build.Utilities;

using ParseArgs = Microsoft.Build.Evaluation.Expander.ArgumentParser;

Expand Down Expand Up @@ -875,6 +876,25 @@ internal static bool TryExecuteWellKnownFunction(string methodName, Type receive
}
}
}
else if (receiverType == typeof(ToolLocationHelper))
{
if (string.Equals(methodName, nameof(ToolLocationHelper.GetPlatformSDKLocation), StringComparison.OrdinalIgnoreCase))
{
if (ParseArgs.TryGetArgs(args, out string? arg0, out string? arg1) && arg0 != null && arg1 != null)
{
returnVal = ToolLocationHelper.GetPlatformSDKLocation(arg0, arg1);
return true;
}
}
else if (string.Equals(methodName, nameof(ToolLocationHelper.GetPlatformSDKDisplayName), StringComparison.OrdinalIgnoreCase))
{
if (ParseArgs.TryGetArgs(args, out string? arg0, out string? arg1) && arg0 != null && arg1 != null)
{
returnVal = ToolLocationHelper.GetPlatformSDKDisplayName(arg0, arg1);
return true;
}
}
}
else if (string.Equals(methodName, nameof(Regex.Replace), StringComparison.OrdinalIgnoreCase) && args.Length == 3)
{
if (ParseArgs.TryGetArgs(args, out string? arg1, out string? arg2, out string? arg3) && arg1 != null && arg2 != null && arg3 != null)
Expand Down
1 change: 1 addition & 0 deletions src/Build/Microsoft.Build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

<ItemGroup>
<ProjectReference Include="..\Framework\Microsoft.Build.Framework.csproj" />
<ProjectReference Include="..\Utilities\Microsoft.Build.Utilities.csproj" />
<ProjectReference Include="..\StringTools\StringTools.csproj" />
<PackageReference Include="Microsoft.VisualStudio.SolutionPersistence" PrivateAssets="all"/>
<PackageReference Include="System.Configuration.ConfigurationManager" />
Expand Down
Loading