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
37 changes: 34 additions & 3 deletions src/Shared/TaskFactoryUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@

using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using Microsoft.Build.Shared.FileSystem;
using Microsoft.Build.Framework;
#if NETFRAMEWORK
using Microsoft.IO;
#else
using System.IO;
#endif

namespace Microsoft.Build.Shared
{
Expand Down Expand Up @@ -136,9 +140,9 @@ public static List<string> ExtractUniqueDirectoriesFromAssemblyPaths(List<string
if (!string.IsNullOrEmpty(assemblyPath) && FileSystems.Default.FileExists(assemblyPath))
{
string? directory = Path.GetDirectoryName(assemblyPath);
if (!string.IsNullOrEmpty(directory) && seenDirectories.Add(directory))
if (!string.IsNullOrEmpty(directory) && seenDirectories.Add(directory!))
{
directories.Add(directory);
directories.Add(directory!);
}
}
}
Expand Down Expand Up @@ -267,5 +271,32 @@ public static bool ShouldCompileForOutOfProcess(IBuildEngine taskFactoryEngineCo

return null;
}

/// <summary>
/// Resolves a potentially relative source code file path for inline task factories.
/// In multithreaded mode (/mt), relative paths are resolved relative to the project file directory
/// rather than the current working directory. In other modes, the path is returned unchanged.
/// </summary>
/// <param name="path">The source code file path to resolve (may be relative or absolute).</param>
/// <param name="isMultiThreadedBuild">Whether the build is running in multithreaded mode.</param>
/// <param name="projectDirectory">The directory of the project file.</param>
/// <returns>The resolved absolute path in multithreaded mode, or the original path otherwise.</returns>
/// <remarks>
/// This method only modifies path resolution in multithreaded builds to maintain
/// backward compatibility with existing multi-process build behavior.
/// </remarks>
public static string ResolveTaskSourceCodePath(string path, bool isMultiThreadedBuild, string projectDirectory)
{
// Path.IsPathFullyQualified is not available in .NET Standard 2.0
// in .NET Framework it's provided by package and in .NET it's built-in
#if NETFRAMEWORK || NET
if (!isMultiThreadedBuild || Path.IsPathFullyQualified(path))
{
return path;
}
#endif

return Path.Combine(projectDirectory, path);
}
}
}
Loading