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
117 changes: 0 additions & 117 deletions src/Tasks/Common/ProcessTaskEnvironmentDriver.cs

This file was deleted.

17 changes: 9 additions & 8 deletions src/Tasks/Common/TaskEnvironmentDefaults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,24 @@
// Provides a default TaskEnvironment for single-threaded MSBuild execution.
// When MSBuild supports IMultiThreadableTask, it sets TaskEnvironment directly.
// This fallback ensures tasks work with older MSBuild versions that do not set it.
//
// Delegates to MSBuild's public TaskEnvironment.Fallback API
// (see https://github.com/dotnet/msbuild/pull/13462) so we no longer carry our
// own polyfill driver implementation.

#if NETFRAMEWORK

using System;

namespace Microsoft.Build.Framework
{
internal static class TaskEnvironmentDefaults
{
/// <summary>
/// Creates a default TaskEnvironment backed by the current process environment.
/// Uses Environment.CurrentDirectory as the project directory, which in single-threaded
/// MSBuild is set to the project directory before task execution.
/// Returns the MSBuild-provided fallback TaskEnvironment, which is backed by the
/// current process environment and uses Environment.CurrentDirectory as the project
/// directory.
/// </summary>
internal static TaskEnvironment Create() =>
new TaskEnvironment(new ProcessTaskEnvironmentDriver(Environment.CurrentDirectory));
internal static TaskEnvironment Create() => TaskEnvironment.Fallback;

Check failure on line 23 in src/Tasks/Common/TaskEnvironmentDefaults.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TestBuild: linux (x64))

src/Tasks/Common/TaskEnvironmentDefaults.cs#L23

src/Tasks/Common/TaskEnvironmentDefaults.cs(23,69): error CS0117: (NETCORE_ENGINEERING_TELEMETRY=Build) 'TaskEnvironment' does not contain a definition for 'Fallback'

Check failure on line 23 in src/Tasks/Common/TaskEnvironmentDefaults.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TestBuild: linux (arm64))

src/Tasks/Common/TaskEnvironmentDefaults.cs#L23

src/Tasks/Common/TaskEnvironmentDefaults.cs(23,69): error CS0117: (NETCORE_ENGINEERING_TELEMETRY=Build) 'TaskEnvironment' does not contain a definition for 'Fallback'

Check failure on line 23 in src/Tasks/Common/TaskEnvironmentDefaults.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build AoT: macOS (x64))

src/Tasks/Common/TaskEnvironmentDefaults.cs#L23

src/Tasks/Common/TaskEnvironmentDefaults.cs(23,69): error CS0117: (NETCORE_ENGINEERING_TELEMETRY=Build) 'TaskEnvironment' does not contain a definition for 'Fallback'

Check failure on line 23 in src/Tasks/Common/TaskEnvironmentDefaults.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TestBuild: macOS (x64))

src/Tasks/Common/TaskEnvironmentDefaults.cs#L23

src/Tasks/Common/TaskEnvironmentDefaults.cs(23,69): error CS0117: (NETCORE_ENGINEERING_TELEMETRY=Build) 'TaskEnvironment' does not contain a definition for 'Fallback'

Check failure on line 23 in src/Tasks/Common/TaskEnvironmentDefaults.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci (Build TestBuild: macOS (arm64))

src/Tasks/Common/TaskEnvironmentDefaults.cs#L23

src/Tasks/Common/TaskEnvironmentDefaults.cs(23,69): error CS0117: (NETCORE_ENGINEERING_TELEMETRY=Build) 'TaskEnvironment' does not contain a definition for 'Fallback'

Check failure on line 23 in src/Tasks/Common/TaskEnvironmentDefaults.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci

src/Tasks/Common/TaskEnvironmentDefaults.cs#L23

src/Tasks/Common/TaskEnvironmentDefaults.cs(23,69): error CS0117: (NETCORE_ENGINEERING_TELEMETRY=Build) 'TaskEnvironment' does not contain a definition for 'Fallback'

Check failure on line 23 in src/Tasks/Common/TaskEnvironmentDefaults.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci

src/Tasks/Common/TaskEnvironmentDefaults.cs#L23

src/Tasks/Common/TaskEnvironmentDefaults.cs(23,69): error CS0117: (NETCORE_ENGINEERING_TELEMETRY=Build) 'TaskEnvironment' does not contain a definition for 'Fallback'

Check failure on line 23 in src/Tasks/Common/TaskEnvironmentDefaults.cs

View check run for this annotation

Azure Pipelines / dotnet-sdk-public-ci

src/Tasks/Common/TaskEnvironmentDefaults.cs#L23

src/Tasks/Common/TaskEnvironmentDefaults.cs(23,69): error CS0117: (NETCORE_ENGINEERING_TELEMETRY=Build) 'TaskEnvironment' does not contain a definition for 'Fallback'
}
}

#endif
#endif
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