-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix: Show source project in graph build errors for invalid project references #12672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: vs18.0
Are you sure you want to change the base?
Conversation
|
Hello @@copilot, I noticed that you’re changing an .swr file or any file under src/Package/MSBuild.VSSetup.. Please make sure to validate this change by an experimental VS insertion. This is accomplished by pushing to an exp/* branch, which requires write permissions to this repo. |
Co-authored-by: baronfel <[email protected]>
Co-authored-by: baronfel <[email protected]>
Co-authored-by: baronfel <[email protected]>
Co-authored-by: baronfel <[email protected]>
|
@copilot this grammar is horrendous:
Better phrasing would be:
|
Co-authored-by: baronfel <[email protected]>
Updated the error message grammar. The new format is: This follows your suggested phrasing and removes the redundant "The project file could not be loaded" text that was appearing twice. (71cf137) |
src/Build/Graph/GraphBuilder.cs
Outdated
| string errorDetails = ex.BaseMessage; | ||
| const string genericPrefix = "The project file could not be loaded. "; | ||
| if (errorDetails.StartsWith(genericPrefix, StringComparison.Ordinal)) | ||
| { | ||
| errorDetails = errorDetails.Substring(genericPrefix.Length); | ||
| } | ||
|
|
||
| string enrichedMessage = ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword( | ||
| "ProjectGraphProjectFileCannotBeLoadedWithReferrers", | ||
| configurationMetadata.ProjectFullPath, | ||
| referrerList, | ||
| errorDetails); | ||
|
|
||
| throw new InvalidProjectFileException( | ||
| ex.ProjectFile ?? configurationMetadata.ProjectFullPath, | ||
| ex.LineNumber, | ||
| ex.ColumnNumber, | ||
| ex.EndLineNumber, | ||
| ex.EndColumnNumber, | ||
| enrichedMessage, | ||
| ex.ErrorSubcategory, | ||
| ex.ErrorCode, | ||
| ex.HelpKeyword, | ||
| ex.InnerException); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot this approach is too fragile - it's specific to the English error message and also the specific grammar of the message. We need to throw the better message in the projectInstanceFactory itself, which means we may need to push additional context into that factory for the graph mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the fragile string manipulation. The approach now simply prepends "Referenced by: {referrers}. " to the complete original error message without any assumptions about its format or language. The error message is now:
Referenced by: /tmp/repro/repro.csproj. The project file could not be loaded. Could not find file '/tmp/repro/InexistentOrTypo.csproj'.
This makes it language-agnostic and not dependent on the specific error message structure. (commit hash will be in the next push)
Co-authored-by: baronfel <[email protected]>
Problem
When building with the
-graphoption, errors about missing or invalid project references don't indicate which project is the source of the reference. This makes it challenging to troubleshoot issues in large solutions with multiple projects.Solution
This PR tracks which projects reference each project during graph construction. When a project fails to load, the exception is enriched with information about the referring project(s).
Error Message Format:
Changes
_projectReferrersConcurrentDictionary to track which projects reference each project during graph constructionParseReferences()to record referrers when submitting projects for parsingParseProject()to catchInvalidProjectFileExceptionand enrich it with referrer information before re-throwingImplementation Approach
The solution uses a simple prepend approach that is language-agnostic and not dependent on error message format. Instead of manipulating the error message string, it simply prepends "Referenced by: {referrers}. " to whatever the original error message is, making it work correctly regardless of locale or specific error message structure.
Testing
Fixes #12671
Original prompt
This section details on the original issue you should resolve
<issue_title>Invalid project references do not indicate source project in
-graphbuilds</issue_title><issue_description>### Describe the bug
When building with the
-graphoption enabled, there is no indication about which project is the source of one or more invalid project references.This makes it challenging to understand which project introduced an invalid reference -- particularly in large solution containing multiple projects, where there are multiple references to the same project, some valid and some not.
This problem does not occur without the
-graphoption, as the source project is then clearly listed; this appears to be a regression specific to graph-mode builds. Consider simplifying troubleshoot graph builds by always printing the source project name(s).To Reproduce
Create
repro.csprojcontaining:Run a regular build:
In this case, the build warning can be associated with the source project (repro mentioned right above.)
Run a graph build:
Observed result: build fails without ever mentioning the source project that introduced the invalid reference. Instead, the referenced target project is mentioned twice.
Expected result: build fails with an error, but gives clear indication that
repro.csprojwas the source of the invalid project reference.Similar results are apparent when turning off the terminal logger.
Compare a regular build, which clearly indicates the source, both during build and in the summary:
While the graph build lists just the invalid reference target, but not its source:
Further technical details
details of dotnet --info
.NET SDK:
Version: 10.0.100-rc.2.25502.107
Commit: 89c8f6a112
Workload version: 10.0.100-rc.2.25513.4
MSBuild version: 18.0.0-preview-25502-107+89c8f6a11
Runtime Environment:
OS Name: Mac OS X
OS Version: 15.7
OS Platform: Darwin
RID: osx-arm64
Base Path: /usr/local/share/dotnet/sdk/10.0.100-rc.2.25502.107/
Host:
Version: 10.0.0-rc.2.25502.107
Architecture: arm64
Commit: 89c8f6a112
.NET SDKs installed:
10.0.100-rc.2.25502.107 [/usr/local/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 10.0.0-rc.2.25502.107 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 10.0.0-rc.2.25502.107 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
...
Fixes #12671
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.