Skip to content

Conversation

JoeRobich
Copy link
Member

@JoeRobich JoeRobich commented Jul 21, 2025

When first loading the .NET Core BuildHost we will launch it with the dotnet CLI from Path. We will then use the project path to determine the usable MSBuild instance. If that instance requires starting from a different dotnet install location, then we will restart the .NET Core BuildHost, so we can use the necessary SDK for project loading.

Resolves dotnet/vscode-csharp#8425

@JoeRobich JoeRobich requested review from a team as code owners July 21, 2025 15:06
@JoeRobich JoeRobich force-pushed the dev/jorobich/find-buildhost-dotnet branch from 02e963c to 584999e Compare July 21, 2025 22:28
@JoeRobich
Copy link
Member Author

@jasonmalinowski @dibarbet Please take a look.

@RikkiGibson
Copy link
Member

The "Resolves" issue link looks like an old PR unrelated to this area

@JoeRobich
Copy link
Member Author

The "Resolves" issue link looks like an old PR unrelated to this area

Thanks, silly me using a vscode-csharp issue number here.

@JoeRobich JoeRobich requested review from jasonmalinowski, dibarbet and a team July 22, 2025 00:58
if (msbuildLocation is not null && GetProcessPath() is { } processPath)
{
// The layout of the SDK is such that the dotnet executable is always at the same relative path from the MSBuild location.
dotnetPath = Path.GetFullPath(Path.Combine(msbuildLocation.Path, $"../../{DotnetExecutable}"));
Copy link
Member

Choose a reason for hiding this comment

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

do we need to save the dotnetPath outside of this call? Presumably subsequent calls to reload the project should likely start with this new dotnet instead of trying from scratch?

Copy link
Member

Choose a reason for hiding this comment

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

Once the build host has been cached in the _processes map, it'll just get reused right away.

Comment on lines 133 to 135
// We need to relaunch the .NET BuildHost from a different dotnet instance.
reload = true;
await buildHostProcess.DisposeAsync().ConfigureAwait(false);
Copy link
Member

Choose a reason for hiding this comment

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

It seems this logic needs to be outside the if (!_processes.TryGetValue(buildHostKind, out var buildHostProcess)) check; because if you were to load several projects at once, once that had a usable MSBuild for the project, we'll cache that in _processes, and later ones wouldn't check again. That said, I think the only way you'd hit this in practice is if you have a solution that spans more than one global.json which isn't really supported by anything.

Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we're better off doing something like:

public async Task<RemoteBuildHost> GetBuildHostAsync(BuildHostProcessKind buildHostKind, CancellationToken cancellationToken)

where BuildHostProcessKind becomes a poor-mans discriminated union like:

record BuildHostProcessKind();
record DotNetHostProcess(string? dotnetPath) : BuildHostProcessKind();
record NetFrameworkHostProcess() : BuildHostProcessKind();

and then that way it's clear that way the path is integral to the kind.

Copy link
Member Author

Choose a reason for hiding this comment

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

My goal for this PR was just to better handle the single SDK BuildHost scenario.

I like your suggestion for supporting multiple .NET Core build hosts. However, I think adding support that should be in a follow up.

@JoeRobich JoeRobich force-pushed the dev/jorobich/find-buildhost-dotnet branch from f34e305 to 3355a66 Compare July 29, 2025 07:04
- Restored removed BuildHost methods.
- Separated MSBuild instance finding from loading
- Removed loop in favor of a single relaunch
@JoeRobich JoeRobich force-pushed the dev/jorobich/find-buildhost-dotnet branch from 3355a66 to 8d5a625 Compare July 29, 2025 07:05
@JoeRobich
Copy link
Member Author

@dibarbet @jasonmalinowski Ready for another review.

@JoeRobich JoeRobich merged commit 9c6403e into dotnet:main Aug 5, 2025
28 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Aug 5, 2025
@RikkiGibson RikkiGibson modified the milestones: Next, 18.0 P1 Aug 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[NET10] [MacOS] Problems loading project with existing file open in editor
4 participants