Skip to content

Refactor VSHostObject credential extraction for COM compatibility and out-of-process execution#52856

Merged
YuliiaKovalova merged 1 commit intorelease/10.0.3xxfrom
dev/ykovalova/add_com_support_to_containers_rebased
Feb 6, 2026
Merged

Refactor VSHostObject credential extraction for COM compatibility and out-of-process execution#52856
YuliiaKovalova merged 1 commit intorelease/10.0.3xxfrom
dev/ykovalova/add_com_support_to_containers_rebased

Conversation

@YuliiaKovalova
Copy link
Member

This PR refactors the VSHostObject class to improve credential extraction from the Visual Studio host object but still maintains backward compatibility with the existing approach.

This is Step 1 of enabling enhanced container task execution capabilities:

  1. Out-of-process MSBuild execution: Currently, the Container task executes in-proc, collects credentials, and passes them to out-of-process executions. This refactoring enables executing the Container task in MSBuild.exe out-of-proc directly.
  2. COM compatibility for .NET Container task: This change prepares the task to be COM-compatible. While not active yet due to lack of app host support, once integrated into the SDK, it can be enabled by default.

Copilot AI review requested due to automatic review settings February 5, 2026 18:01
Copy link
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 refactors the VSHostObject class to enable COM compatibility and out-of-process MSBuild execution for the Container task. The refactoring introduces a new credential extraction method using reflection to invoke QueryAllTaskItems via COM interop, while maintaining backward compatibility with the existing IEnumerable<ITaskItem> approach.

Changes:

  • Refactored VSHostObject to use reflection-based credential extraction with JSON deserialization, supporting both new COM-based host objects and legacy IEnumerable<ITaskItem> implementations
  • Updated CreateNewImage task to extract credentials and set them as process-wide environment variables with try-finally cleanup
  • Modified CreateNewImageToolTask to use the new VSHostObject API with pattern matching
  • Enabled VSHostObject.cs compilation for all target frameworks (removed from net472-only exclusion list)

Reviewed changes

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

File Description
VSHostObject.cs Complete refactor introducing primary constructor, reflection-based COM interop for QueryAllTaskItems, JSON deserialization, and backward-compatible fallback to IEnumerable<ITaskItem>
CreateNewImage.cs Added credential extraction logic that sets process-wide environment variables with try-finally cleanup, and split execution into separate ExecuteAsyncCore method
CreateNewImageToolTask.cs Updated to use new VSHostObject constructor and TryGetCredentials() method with pattern matching
Microsoft.NET.Build.Containers.csproj Removed conditional exclusion of VSHostObject.cs from non-net472 builds, making it available for all target frameworks

@baronfel baronfel requested a review from a team February 5, 2026 19:25
@baronfel baronfel added Area-VS Area-Containers Related to dotnet SDK containers functionality labels Feb 5, 2026
@YuliiaKovalova YuliiaKovalova merged commit efe7617 into release/10.0.3xx Feb 6, 2026
33 of 34 checks passed
@YuliiaKovalova YuliiaKovalova deleted the dev/ykovalova/add_com_support_to_containers_rebased branch February 6, 2026 18:33
@YuliiaKovalova YuliiaKovalova self-assigned this Feb 11, 2026
YuliiaKovalova added a commit to dotnet/msbuild that referenced this pull request Mar 9, 2026
…mple (#13324)

Update `remote-host-object.md` with documentation for the MSBuild
apphost changes.

### What's added

1. **Shipping `Microsoft.Build.Framework.tlb` with the .NET SDK** -
documents that the `.tlb` ships starting from 10.0.3xx, explains why
it's needed (COM marshaling for `ITaskHost` across process boundaries),
what capabilities it enables (ROT host objects, registration-free COM,
parity with VS), and shows the SDK layout.

2. **Practical `IDispatch` example** - end-to-end example showing how a
VS host object (WebTools) serializes task items to JSON via
`QueryAllTaskItems`, and how the SDK Container task
([dotnet/sdk#52856](dotnet/sdk#52856)) calls it
via `IDispatch` (reflection `InvokeMember`) with a fallback to the
legacy in-proc path.

Related PRs:
- #13175 (Add App Host Support for MSBuild)
- dotnet/sdk#52856 (Refactor VSHostObject for COM compatibility)
- [WebTools PR
701336](https://dev.azure.com/devdiv/DevDiv/_git/WebTools/pullrequest/701336)

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Rainer Sigwald <raines@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Containers Related to dotnet SDK containers functionality Area-VS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants