Skip to content

Migrate ResolveTargetingPackAssets to IMultiThreadableTask - #49

Closed
SimaTian wants to merge 1 commit into
multithreading-polyfillsfrom
migrate-resolve-targeting-pack-assets
Closed

SimaTian wants to merge 1 commit into
multithreading-polyfillsfrom
migrate-resolve-targeting-pack-assets

Conversation

@SimaTian

Copy link
Copy Markdown
Owner

WIP — Migration in progress.

@SimaTian

Copy link
Copy Markdown
Owner Author

Closing: PR is empty (no code changes). Task is available for migration.

@SimaTian SimaTian closed this Feb 10, 2026
@SimaTian

Copy link
Copy Markdown
Owner Author

Migration Review: ResolveTargetingPackAssets

Status: ❌ No migration implemented

This PR contains 0 changed files (empty commit). The PR was closed with the note "PR is empty (no code changes). Task is available for migration."

Required for migration (per migration guide):

  1. Determine pattern: Analyze the existing ResolveTargetingPackAssets task code for forbidden API usage (Path.GetFullPath, File.*, Environment.*, ProcessStartInfo, etc.)

  2. If no forbidden APIs (Pattern A - Attribute-Only):

    • Add [MSBuildMultiThreadableTask] attribute to the task class
  3. If forbidden APIs are used (Pattern B - Interface-Based):

    • Implement IMultiThreadableTask interface
    • Add TaskEnvironment property (public ITaskEnvironment TaskEnvironment { get; set; })
    • Replace all forbidden API calls:
      • Path.GetFullPath(path) → TaskEnvironment.GetAbsolutePath(path)
      • Environment.GetEnvironmentVariable(name) → TaskEnvironment.GetEnvironmentVariable(name)
      • Environment.SetEnvironmentVariable(name, value) → TaskEnvironment.SetEnvironmentVariable(name, value)
      • Environment.CurrentDirectory → TaskEnvironment.ProjectDirectory
      • new ProcessStartInfo(...) → TaskEnvironment.GetProcessStartInfo()
    • Ensure all File/Directory APIs use absolute paths
    • Do NOT null-check TaskEnvironment
  4. Tests required:

    • Verify IMultiThreadableTask implementation (for Pattern B)
    • Verify MSBuildMultiThreadableTask attribute
    • Verify correct path resolution with non-default project directory
    • Tests must FAIL on improperly migrated task

This PR needs to be reopened with actual migration code before it can be reviewed for correctness.

@SimaTian

Copy link
Copy Markdown
Owner Author

Code Review: Migration to IMultiThreadableTask

PR #49: Migrate ResolveTargetingPackAssets

Checklist

  • Base class changed from Task/TaskBase to MultiThreadableTask
  • Path.GetFullPath() replaced with TaskEnvironment.GetAbsolutePath() (N/A — not used in this file)
  • Environment.GetEnvironmentVariable() replaced with TaskEnvironment.GetEnvironmentVariable()
  • Environment.SetEnvironmentVariable() replaced with TaskEnvironment.SetEnvironmentVariable() (N/A — not used in this file)
  • No remaining global process state usage
  • ProcessStartInfo uses TaskEnvironment.GetProcessStartInfo() where applicable (N/A — not used)

Findings

This PR contains an empty commit with no code changes (0 additions, 0 deletions, 0 changed files). The ResolveTargetingPackAssets class on the branch still extends TaskBase.

Critical issue — Environment.GetEnvironmentVariable() usage:
There is a static field:
csharp private static readonly bool s_allowCacheLookup = Environment.GetEnvironmentVariable(ALLOW_TARGETING_PACK_CACHING) != ""0"";
This reads an environment variable at class initialization time using the global Environment.GetEnvironmentVariable() API. Per the spec, this must be replaced with TaskEnvironment.GetEnvironmentVariable().

Important note: Since s_allowCacheLookup is a static readonly field initialized via a static initializer, it cannot use TaskEnvironment (which is an instance property). This will require a design change — the field should become an instance-level property or the check should be moved into ExecuteCore() where TaskEnvironment is available. For example:
csharp bool allowCacheLookup = TaskEnvironment.GetEnvironmentVariable(ALLOW_TARGETING_PACK_CACHING) != ""0"";
evaluated at the start of ExecuteCore().

What needs to be done:

  1. Change the base class from TaskBase to MultiThreadableTask.
  2. Replace the static Environment.GetEnvironmentVariable() usage with an instance-level TaskEnvironment.GetEnvironmentVariable() call, moving the logic into ExecuteCore() or a lazy-evaluated instance property.
  3. This is one of the more complex migrations in this batch because of the static field design pattern.

Verdict

NEEDS CHANGES — No migration has been performed. The commit is empty. The Environment.GetEnvironmentVariable() call requires both a base class change and a refactor from static to instance-level evaluation.

@SimaTian

Copy link
Copy Markdown
Owner Author

Migration Guide Review: PR #49 — ResolveTargetingPackAssets

Verdict: ❌ No migration implemented (empty commit). Requires Pattern B — HIGHEST COMPLEXITY.

Source Code Analysis

Forbidden API Scan — CRITICAL ISSUES FOUND:

  1. Environment.GetEnvironmentVariable() ❌ (Rule 2 — must replace):

    private static readonly bool s_allowCacheLookup = Environment.GetEnvironmentVariable(ALLOW_TARGETING_PACK_CACHING) != ""0"";
    

    → Must replace with TaskEnvironment.GetEnvironmentVariable(ALLOW_TARGETING_PACK_CACHING)

    ⚠️ Design challenge: This is a static readonly field initialized in the static constructor. TaskEnvironment is an instance property, so this must be refactored to instance-level evaluation (e.g., computed in ExecuteCore() or as a lazy instance property).

  2. File.Exists() ⚠️ (Rule 3 — must use absolute paths):

    • File.Exists(platformManifestPath)
    • File.Exists(packageOverridesPath)
      All paths from Path.Combine() with targetingPackRoot — should be absolute.
  3. File.ReadAllText() ⚠️ (Rule 3 — must use absolute paths):

    • File.ReadAllText(packageOverridesPath) in CreatePackageOverride()
  4. Directory.Exists() ⚠️ (Rule 3 — must use absolute paths):

    • Directory.Exists(targetingPackRoot)
    • Directory.Exists(targetingPackDllFolder)
  5. Directory.GetFiles() ⚠️ (Rule 3 — must use absolute paths):

    • Directory.GetFiles(targetingPackAssetPath, ""*.dll"") in AddNetStandardTargetingPackAssets()
  6. XDocument.Load() ⚠️ (Rule 3 — must use absolute paths):

    • XDocument.Load(definition.FrameworkListPath) in AddItemsFromFrameworkList()

Migration Assessment:

Pattern B (Interface-Based) is required due to Environment.GetEnvironmentVariable() usage.

Required Changes:

  1. Add [MSBuildMultiThreadableTask] attribute
  2. Implement IMultiThreadableTask interface
  3. Add public ITaskEnvironment TaskEnvironment { get; set; } property
  4. Refactor s_allowCacheLookup: Change from static readonly field using Environment.GetEnvironmentVariable() to instance-level evaluation using TaskEnvironment.GetEnvironmentVariable(). E.g.:
    // In ExecuteCore() or as instance property:
    bool allowCacheLookup = TaskEnvironment.GetEnvironmentVariable(ALLOW_TARGETING_PACK_CACHING) != ""0"";
    This will need to be threaded through to Resolve() and AddItemsFromFrameworkList() which currently reference s_allowCacheLookup.
  5. Do NOT null-check TaskEnvironment (Rule 5)
  6. Verify all File.*, Directory.*, and XDocument.Load() receive absolute paths
  7. Note: The Resolve() method is static — it may need to become instance or receive TaskEnvironment as parameter to access GetEnvironmentVariable()
  8. Add migration tests:
    • Verify IMultiThreadableTask implementation
    • Verify MSBuildMultiThreadableTask attribute
    • Verify Environment.GetEnvironmentVariable is replaced
    • Test with non-default project directory
    • Tests must FAIL if migration is reverted

Missing from this PR:

  • [MSBuildMultiThreadableTask] attribute
  • IMultiThreadableTask implementation
  • TaskEnvironment property
  • Environment.GetEnvironmentVariable() → TaskEnvironment.GetEnvironmentVariable()
  • Refactor from static to instance-level environment variable access
  • Migration tests
  • Any code changes at all (empty commit)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant