Refactor VSHostObject credential extraction for COM compatibility and out-of-process execution#52856
Merged
YuliiaKovalova merged 1 commit intorelease/10.0.3xxfrom Feb 6, 2026
Conversation
Contributor
There was a problem hiding this comment.
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
VSHostObjectto use reflection-based credential extraction with JSON deserialization, supporting both new COM-based host objects and legacyIEnumerable<ITaskItem>implementations - Updated
CreateNewImagetask to extract credentials and set them as process-wide environment variables with try-finally cleanup - Modified
CreateNewImageToolTaskto use the newVSHostObjectAPI with pattern matching - Enabled
VSHostObject.cscompilation 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
approved these changes
Feb 5, 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: