Skip to content

Migrate WriteAppConfigWithSupportedRuntime to IMultiThreadableTask#53957

Open
SimaTian wants to merge 2 commits intodotnet:mainfrom
SimaTian:migrate-write-app-config-supported-runtime
Open

Migrate WriteAppConfigWithSupportedRuntime to IMultiThreadableTask#53957
SimaTian wants to merge 2 commits intodotnet:mainfrom
SimaTian:migrate-write-app-config-supported-runtime

Conversation

@SimaTian
Copy link
Copy Markdown
Member

Migrates WriteAppConfigWithSupportedRuntime to support IMultiThreadableTask.

Changes

  • Adds [MSBuildMultiThreadableTask] attribute and implements IMultiThreadableTask.
  • Routes output file write (FileStream) and input read (XDocument.Load) through TaskEnvironment.GetAbsolutePath().
  • Uses AbsolutePath.Value for the reserved FullPath MSBuild well-known metadata key (reserved keys must be absolute).
  • Adds 6 behavioral tests: decoy-CWD routing, cross-thread env isolation, with/without TaskEnvironment parity, null AppConfig input path, 8-way concurrent execution.

Supersedes

Part of the split of stuck merge-group PR #52936. This is the 3-of-5 split for WriteAppConfigWithSupportedRuntime.

SimaTian and others added 2 commits April 17, 2026 11:29
- Add [MSBuildMultiThreadableTask] attribute
- Implement IMultiThreadableTask interface with TaskEnvironment property
- Route all path operations through TaskEnvironment with null-safe fallbacks
- Use AbsolutePath.OriginalValue for output metadata fidelity
- Add comprehensive multithreading tests covering:
  - Decoy CWD path resolution
  - Cross-thread isolation with different environments
  - Multi-process parity (with and without TaskEnvironment)
  - Task environment resolved path verification
  - Null AppConfigFile handling
  - Concurrent execution with different framework versions

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- WriteAppConfigWithSupportedRuntime.cs: use AbsolutePath.Value (not OriginalValue)
  when setting the reserved 'FullPath' item metadata. 'FullPath' is contractually
  an absolute path; setting it to OriginalValue (possibly relative) misled
  downstream consumers and defeated the purpose of pinning the write location.
- GivenAWriteAppConfigWithSupportedRuntimeMultiThreading.cs: replace hardcoded
  'obj\\Debug\\output.config' literal with Path.Combine to keep the test
  cross-platform (skill D9).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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

This PR migrates WriteAppConfigWithSupportedRuntime to be compatible with MSBuild’s multithreaded task execution model by implementing IMultiThreadableTask and routing path I/O through TaskEnvironment to avoid reliance on process-wide state (like CWD).

Changes:

  • Marks the task as multi-threadable and adds TaskEnvironment support for path resolution.
  • Updates input (app.config) load and output write paths to resolve via TaskEnvironment.GetAbsolutePath().
  • Adds a new unit test suite covering CWD decoy routing, cross-thread isolation, parity, null inputs, and concurrent execution.

Reviewed changes

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

File Description
src/Tasks/Microsoft.NET.Build.Tasks/WriteAppConfigWithSupportedRuntime.cs Adds IMultiThreadableTask + TaskEnvironment-based absolute path resolution for file I/O.
src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/GivenAWriteAppConfigWithSupportedRuntimeMultiThreading.cs Adds behavioral tests for multithreaded/task-environment correctness and concurrency scenarios.

#nullable disable

using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
Comment on lines 60 to +62
}

OutputAppConfigFile.SetMetadata("FullPath", outputPath.Value);
using Xunit;

namespace Microsoft.NET.Build.Tasks.UnitTests
{
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.

2 participants