Skip to content

Conversation

@tmat
Copy link
Member

@tmat tmat commented Dec 7, 2025

Refactors BuildHost and MSBuildProjectLoader to allow dotnet-watch to populate workspace in-proc based on already evaluated ProjectInstances (loaded via ProjectGraph).

  • Factors language specific retrieval of command line arguments out of ProjectFile into separate types: XyzProjectCommandLineProvider.
  • Factors construction of ProjectFileInfo based on ProjectInstance into a separate type: ProjectInstanceReader. The reader takes project instance and optionally MSBuild Project and extracts the necessary info from its properties and items. The Project is optional - it is only needed to populate FileGlobs.
  • Adds HotReloadMSBuildWorkspace - this is a replacement for dotnet-watch's IncrementalMSBuildWorkspace
  • Adds interface IProjectFileInfoProvider that abstract away retrieval of ProjectFileInfos. MSBuildWorkspace uses an implementation that dispatches to OOP while HotReloadMSBuildWorkspace uses impl that calculates the information directly (in-proc) from project instances provided by dotnet-watch.
  • Updates BuildHost project to build first-class NuGet package.

dotnet-watch usage: dotnet/sdk#52163

@tmat tmat marked this pull request as ready for review December 10, 2025 19:24
@tmat tmat requested review from a team as code owners December 10, 2025 19:24
@tmat
Copy link
Member Author

tmat commented Dec 10, 2025

@jasonmalinowski @DustinCampbell ptal

Copy link
Member

@jasonmalinowski jasonmalinowski left a comment

Choose a reason for hiding this comment

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

Leaving comments so far; no real concerns so far.

Copy link
Member

Choose a reason for hiding this comment

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

ImmutableArray<DocumentInfo> MapDocuments(ProjectId mappedProjectId, IReadOnlyList<DocumentInfo> documents)
=> documents.Select(docInfo =>
{
// TODO: can there be multiple documents of the same path in the project?
Copy link
Member

Choose a reason for hiding this comment

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

Just to document it somewhere, yes that can happen if a file is added twice. Or is added as both a source file and an additional file. None of these are "real" scenarios, but can happen in broken project scenarios. The only expectation is we don't crash. There might be a bug here since maybe if a source file is being added as an additional file we might try to reuse the same ID which would be bad in this case. Maybe file a bug for tracking, if we refactor this later this code might go away.

Copy link
Member

@jasonmalinowski jasonmalinowski left a comment

Choose a reason for hiding this comment

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

Fantastic job cleaning this up. Although I imagine there's further refactorings here that will delete some of the code that migrated, I'm much happier to see all the "complexity" of the loading be in Roslyn rather than being in the SDK. That means we can clean it up without cross-cutting changes.

@tmat
Copy link
Member Author

tmat commented Jan 5, 2026

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@tmat tmat merged commit a808023 into dotnet:main Jan 6, 2026
29 checks passed
@tmat tmat deleted the BuildHostHR branch January 6, 2026 03:37
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Jan 6, 2026
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.

2 participants