Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Convert VisualStudioWorkloads to use direct COM - #52650

#52650
Merged
JeremyKuhne merged 3 commits into
dotnet:maindotnet/sdk:mainfrom
JeremyKuhne:vsworkloadJeremyKuhne/sdk:vsworkloadCopy head branch name to clipboard
Jan 29, 2026
Merged

Convert VisualStudioWorkloads to use direct COM#52650
JeremyKuhne merged 3 commits into
dotnet:maindotnet/sdk:mainfrom
JeremyKuhne:vsworkloadJeremyKuhne/sdk:vsworkloadCopy head branch name to clipboard

Conversation

@JeremyKuhne

Copy link
Copy Markdown
Member

This change uses function pointers to avoid overhead and allow AOT scenarios.

VS setup APIs are not part of the Windows SDK and as such aren't filled out via CsWin32. I've defined all of the setup APIs as CsWin32 would. We don't use much of the API surface area, but there is no marshalling here so the code cost is small. If we care to trim out some of these we can #ifdef down to what is actually used.

The patterns used here are similar to what is used in WinForms and WPF. They can be multi-targeted and I've left TFM conditions in this code so I can move the implementations to the utility assembly as I fix other COM usage there.

I'm working on adding the unit tests for the supporting functionality.

Also added a start-vs.cmd for easily starting VS to facilitate running tests on the local .NET.

Copilot AI review requested due to automatic review settings January 23, 2026 01:52
@JeremyKuhne
JeremyKuhne marked this pull request as draft January 23, 2026 01:52
@JeremyKuhne

JeremyKuhne commented Jan 23, 2026

Copy link
Copy Markdown
Member Author

Current before and after for just the changed method:

Method Mean Error StdDev Gen0 Allocated
GetInstalledWorkloads 7.855 ms 0.1307 ms 0.1092 ms 15.6250 341.15 KB
Method Mean Error StdDev Allocated
GetInstalledWorkloads 5.690 ms 0.0131 ms 0.0116 ms 19.66 KB

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This pull request converts Visual Studio workload detection from using COM interop (via the Microsoft.VisualStudio.Setup.Configuration.Interop package) to direct COM invocation using function pointers. This enables AOT compilation scenarios and reduces marshalling overhead.

Changes:

  • Replaced COM interop package with custom COM interface definitions and direct vtable calls
  • Added comprehensive COM infrastructure (ComScope, SafeArrayScope, VARIANT handling, etc.)
  • Refactored VisualStudioWorkloads.cs to use unsafe code with direct COM calls
  • Added start-vs.cmd utility script for development
  • Made minor optimizations in other files (collection expressions, string caching)

Reviewed changes

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

Show a summary per file
File Description
src/Cli/dotnet/Commands/Workload/List/VisualStudioWorkloads.cs Converted to use direct COM calls via custom interfaces; improved string handling with spans
src/Cli/dotnet/Windows/Win32/System/Variant/* New VARIANT marshalling infrastructure for COM interop
src/Cli/dotnet/Windows/Win32/System/Com/* New COM helper types (ComScope, SafeArrayScope, etc.) for resource management
src/Cli/dotnet/Windows/Win32/Foundation/* New Win32 foundation types (BSTR, HRESULT, Error handling, etc.)
src/Cli/dotnet/Microsoft/VisualStudio/Setup/Configuration/* Custom definitions of VS Setup Configuration COM interfaces
src/Cli/dotnet/dotnet.csproj Removed VS Setup interop package; updated CsWin32 configuration
test/dotnet.Tests/dotnet.Tests.csproj Enabled unsafe blocks; removed VS Setup interop package
start-vs.cmd New utility script for launching VS with local SDK
Directory.Packages.props Updated CsWin32 version to 0.3.264

Comment thread src/Cli/dotnet/Windows/Win32/Foundation/BSTR.cs
Comment thread test/dotnet.Tests/dotnet.Tests.csproj
Comment thread Directory.Packages.props Outdated

@baronfel baronfel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Left a few notes about arrangement, and @joeloff should probably look at the VS Setup catalog/win32 definitions as our other most-knowledgeable COM person.

This change uses function pointers to avoid overhead and allow AOT scenarios.

VS setup APIs are not part of the Windows SDK and as such aren't filled out via CsWin32. I've defined all of the setup APIs as CsWin32 would. We don't use much of the API surface area, but there is no marshalling here so the code cost is small. If we care to trim out some of these we can #ifdef down to what is actually used.

The patterns used here are similar to what is used in WinForms and WPF. They can be multi-targeted and I've left TFM conditions in this code so I can move the implementations to the utility assembly as I fix other COM usage there.

I'm working on adding the unit tests for the supporting functionalty.
This additional functionality (and more) can be pulled in as needed from:

- WinForms
- https://github.com/JeremyKuhne/vsinterop
- https://github.com/JeremyKuhne/madowaku
Comment thread eng/Versions.props
Comment thread src/Cli/dotnet/Commands/Workload/List/VisualStudioWorkloads.cs
Comment thread start-vs.cmd
@JeremyKuhne
JeremyKuhne merged commit 3b9489d into dotnet:main Jan 29, 2026
26 checks passed
@JeremyKuhne
JeremyKuhne deleted the vsworkload branch January 29, 2026 17:45
@JeremyKuhne

Copy link
Copy Markdown
Member Author

I didn't squash this one so the more complete definitions for some of the interop stuff is in the history.

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.

5 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.