Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,19 @@ namespace Microsoft.NET.Build.Tasks
/// Tracking issue https://github.com/dotnet/roslyn-project-system/issues/587
/// </summary>
[MSBuildMultiThreadableTask]
public class CollectSDKReferencesDesignTime : TaskBase
public class CollectSDKReferencesDesignTime : TaskBase, IMultiThreadableTask
{
#if NETFRAMEWORK
private TaskEnvironment _taskEnvironment;
public TaskEnvironment TaskEnvironment
{
get => _taskEnvironment ??= TaskEnvironmentDefaults.Create();
set => _taskEnvironment = value;
Comment on lines +21 to +26
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

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

On NETFRAMEWORK, the lazy default TaskEnvironment creates a ProcessTaskEnvironmentDriver(Directory.GetCurrentDirectory()), which enumerates process environment variables and captures the current working directory. That adds side effects/overhead (and contradicts the PR’s stated “zero env-var reads”) even though this task is otherwise pure in-memory. Consider making TaskEnvironment a simple settable property (letting MSBuild supply it) or using a lightweight in-memory driver that doesn’t snapshot process environment/CWD when a fallback is needed.

Copilot uses AI. Check for mistakes.
}
#else
public TaskEnvironment TaskEnvironment { get; set; }
#endif

[Required]
public ITaskItem[] SdkReferences { get; set; }

Expand All @@ -30,14 +41,12 @@ public class CollectSDKReferencesDesignTime : TaskBase
[Output]
public ITaskItem[] SDKReferencesDesignTime { get; set; }

private HashSet<string> ImplicitPackageReferences { get; set; }

protected override void ExecuteCore()
{
ImplicitPackageReferences = GetImplicitPackageReferences(DefaultImplicitPackages);
var implicitPackageReferences = GetImplicitPackageReferences(DefaultImplicitPackages);

var sdkDesignTimeList = new List<ITaskItem>(SdkReferences);
sdkDesignTimeList.AddRange(GetImplicitPackageReferences());
sdkDesignTimeList.AddRange(GetImplicitPackageReferences(implicitPackageReferences));

SDKReferencesDesignTime = sdkDesignTimeList.ToArray();
}
Expand All @@ -64,7 +73,7 @@ internal static HashSet<string> GetImplicitPackageReferences(string defaultImpli
return implicitPackageReferences;
}

private IEnumerable<ITaskItem> GetImplicitPackageReferences()
private IEnumerable<ITaskItem> GetImplicitPackageReferences(HashSet<string> implicitPackageReferences)
{
var implicitPackages = new List<ITaskItem>();
foreach (var packageReference in PackageReferences)
Expand All @@ -73,7 +82,7 @@ private IEnumerable<ITaskItem> GetImplicitPackageReferences()
var isImplicitlyDefinedString = packageReference.GetMetadata(MetadataKeys.IsImplicitlyDefined);
if (string.IsNullOrEmpty(isImplicitlyDefinedString))
{
isImplicitlyDefined = ImplicitPackageReferences.Contains(packageReference.ItemSpec);
isImplicitlyDefined = implicitPackageReferences.Contains(packageReference.ItemSpec);
}
else
{
Expand Down
Loading
Loading