Skip to content

Migrate GenerateSupportedTargetFrameworkAlias to IMultiThreadableTask#53954

Closed
SimaTian wants to merge 3 commits intodotnet:mainfrom
SimaTian:migrate-generate-supported-target-framework-alias
Closed

Migrate GenerateSupportedTargetFrameworkAlias to IMultiThreadableTask#53954
SimaTian wants to merge 3 commits intodotnet:mainfrom
SimaTian:migrate-generate-supported-target-framework-alias

Conversation

@SimaTian
Copy link
Copy Markdown
Member

@SimaTian SimaTian commented Apr 17, 2026

Migrates \GenerateSupportedTargetFrameworkAlias\ to support \IMultiThreadableTask.

Changes

  • Pattern A (pure in-memory): attribute + interface + stub TaskEnvironment. Task only does NuGet framework parsing and string formatting; zero I/O.
  • Adds new \MetadataKeys.DisplayName\ constant and replaces string literals throughout.

Addresses review feedback from #53116

  • ✅ Start-gate pattern (ManualResetEventSlim) replaces Barrier + Parallel.For.
  • ✅ MetadataKeys.DisplayName constant replaces string literals.

Supersedes

Part of the split of stuck merge-group PR #53116. This is the 5-of-5 split for \GenerateSupportedTargetFrameworkAlias.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Migrates GenerateSupportedTargetFrameworkAlias to support MSBuild multithreaded execution via IMultiThreadableTask, and adds dedicated unit tests validating deterministic and concurrent behavior plus DisplayName metadata handling.

Changes:

  • Implement IMultiThreadableTask on GenerateSupportedTargetFrameworkAlias and add a TaskEnvironment property.
  • Add MetadataKeys.DisplayName constant and use it in the task and new tests.
  • Add a dedicated multithreading/behavioral test suite for GenerateSupportedTargetFrameworkAlias.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/Tasks/Microsoft.NET.Build.Tasks/GenerateSupportedTargetFrameworkAlias.cs Implements IMultiThreadableTask and switches DisplayName metadata handling to MetadataKeys.DisplayName.
src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/GivenAGenerateSupportedTargetFrameworkAliasMultiThreading.cs Adds new concurrency + determinism + metadata propagation tests for the task.
src/Tasks/Common/MetadataKeys.cs Adds MetadataKeys.DisplayName constant.

Comment thread src/Tasks/Common/MetadataKeys.cs
Comment thread src/Tasks/Microsoft.NET.Build.Tasks/GenerateSupportedTargetFrameworkAlias.cs Outdated
Comment on lines +57 to +63
var projectDirs = new string[threadCount];
var taskEnvs = new TaskEnvironment[threadCount];
var expectedOutputs = new string[threadCount];
var observedOutputs = new string?[threadCount];
var results = new bool[threadCount];
var exceptions = new Exception?[threadCount];

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.

expectedOutputs is declared but never used. The repo sets TreatWarningsAsErrors=True (Directory.Build.props), so this will fail the build with an unused-variable warning. Remove it or use it in the assertions.

Copilot uses AI. Check for mistakes.
SimaTian and others added 2 commits April 29, 2026 13:47
GenerateSupportedTargetFrameworkAlias is a pure in-memory task that aliases
supported target frameworks. It reads SupportedTargetFramework items, parses
them via NuGet.Frameworks, and outputs SupportedTargetFrameworkAlias items
with DisplayName metadata.

Forbidden API scan: NONE. Task is purely computational (NuGet parsing +
string manipulation), no file/env/console/process access.

Migration approach: Attribute-only + stub IMultiThreadableTask/TaskEnvironment
for API consistency (Pattern A). TaskEnvironment property added per-standard
since task has no environment dependencies.

Added MetadataKeys.DisplayName constant and replaced string literals in
GenerateSupportedTargetFrameworkAlias.cs.

Created comprehensive multithreading test suite:
- GivenAGenerateSupportedTargetFrameworkAliasMultiThreading.cs
- Concurrent correctness via start-gate (ManualResetEventSlim) + explicit tasks
- Real behavioral assertions (aliases correctly produced, DisplayName propagated,
  -windows suffix applied for WPF/WinForms, framework family filtering)
- Uses MetadataKeys.* constants only, no string literals
- No tautologies, each test verifies meaningful task behavior

Review findings addressed:
1. Start-gate pattern (ManualResetEventSlim) instead of Barrier to avoid deadlock
2. Per-task test file (not shared multithreading test suite)
3. MetadataKeys.* constants throughout

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@OvesN OvesN marked this pull request as ready for review May 5, 2026 10:10
@JanProvaznik
Copy link
Copy Markdown
Member

the attribute is already there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants