msbuild icon indicating copy to clipboard operation
msbuild copied to clipboard

Invalid project references do not indicate source project in `-graph` builds

Open nil4 opened this issue 2 months ago • 3 comments

Describe the bug

When building with the -graph option 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 -graph option, 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.csproj containing:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <ProjectReference Include="InexistentOrTypo.csproj" />
  </ItemGroup>
</Project>

Run a regular build:

> dotnet build repro.csproj
Restore complete (0.1s)
  repro net10.0 succeeded with 1 warning(s) (0.1s) → bin/Debug/net10.0/repro.dll
    /usr/local/share/dotnet/sdk/10.0.100-rc.2.25502.107/Microsoft.Common.CurrentVersion.targets(2189,5): warning MSB9008: The referenced project InexistentOrTypo.csproj does not exist.

Build succeeded with 1 warning(s) in 0.4s

In this case, the build warning can be associated with the source project (repro mentioned right above.)

Run a graph build:

> dotnet build repro.csproj -graph
Restore complete (0.1s)
/Users/nil4/dev/repro/InexistentOrTypo.csproj : error MSB4025: The project file could not be loaded. Could not find file '/Users/nil4/dev/repro/InexistentOrTypo.csproj'.

Build failed with 1 error(s) in 0.3s

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.csproj was 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:

> dotnet build repro.csproj -tl:off
  Determining projects to restore...
  Skipping project "/Users/nil4/dev/repro/InexistentOrTypo.csproj" because it was not found.
  Skipping project "/Users/nil4/dev/repro/InexistentOrTypo.csproj" because it was not found.
  All projects are up-to-date for restore.
/usr/local/share/dotnet/sdk/10.0.100-rc.2.25502.107/Microsoft.Common.CurrentVersion.targets(2189,5): warning MSB9008: The referenced project InexistentOrTypo.csproj does not exist. [/Users/nil4/dev/repro/repro.csproj]
  repro -> /Users/nil4/dev/repro/bin/Debug/net10.0/repro.dll

Build succeeded.

/usr/local/share/dotnet/sdk/10.0.100-rc.2.25502.107/Microsoft.Common.CurrentVersion.targets(2189,5): warning MSB9008: The referenced project InexistentOrTypo.csproj does not exist. [/Users/nil4/dev/repro/repro.csproj]
    1 Warning(s)
    0 Error(s)

While the graph build lists just the invalid reference target, but not its source:

> dotnet build repro.csproj -graph -tl:off
  Determining projects to restore...
  Skipping project "/Users/nil4/dev/repro/InexistentOrTypo.csproj" because it was not found.
  Skipping project "/Users/nil4/dev/repro/InexistentOrTypo.csproj" because it was not found.
  All projects are up-to-date for restore.
Static graph construction started.
/Users/nil4/dev/repro/InexistentOrTypo.csproj : error MSB4025: The project file could not be loaded. Could not find file '/Users/nil4/dev/repro/InexistentOrTypo.csproj'.

Build FAILED.

/Users/nil4/dev/repro/InexistentOrTypo.csproj : error MSB4025: The project file could not be loaded. Could not find file '/Users/nil4/dev/repro/InexistentOrTypo.csproj'.
    0 Warning(s)
    1 Error(s)

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]

nil4 avatar Oct 19 '25 19:10 nil4

This is a great report - thank you for the detail. It does seem that the TerminalLogger doesn't keep track of some of the same 'bookkeeping' in graph mode that it does in 'normal' mode. I'm going to move this over to MSBuild where the TerminalLogger is implemented for further investigation.

baronfel avatar Oct 19 '25 19:10 baronfel

Also reported as #9850 but since @baronfel pointed Copilot at this one we can close that one as a dupe?

rainersigwald avatar Oct 20 '25 19:10 rainersigwald

It looks like Copilot soft-landed and then went to the beach (maybe?) Anything we could to to bring it back? ;)

nil4 avatar Nov 24 '25 17:11 nil4