dotnet / dotnet/msbuild

Static graph incorrectly represents multitargeting agnostic projects that depend on multitargeting projects

Open
#4,344 0 comments 0 reactions 0 assignees View on GitHub
Area: Static Graph bug triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 13h
Merged PRs (30d)
133

Description

### Steps to reproduce

Either include a project sample, attach a zipped project, or provide IDE / CLI steps to create the project and repro the behaviour. Example of a project sample:

dirs.proj
```xml






```

1.csproj
```xml


Exe
netcoreapp2.2;net472

```

Command line
```
msbuild dirs.proj /graph /isolate
```
### Expected behavior

Build succeeds

### Actual behavior

```
E:\projects\MSBuildTestProjects\projects\sdk\working\DependencyOn2New\1\1.csproj : error : MSB4252: Project "E:\projects\MSBuildTestProjects\projects\sdk\working\DependencyOn2New\dirs.customProj" has a reference to "E:\projects\MSBuildTestProjects\projects\sdk\worki
ng\DependencyOn2New\1\1.csproj" (default target(s)) but the build result for the reference is not in the engine cache. In isolated builds this could mean one of the following:
E:\projects\MSBuildTestProjects\projects\sdk\working\DependencyOn2New\1\1.csproj : error : - the reference was not explicitly specified as a ProjectReference item in "E:\projects\MSBuildTestProjects\projects\sdk\working\DependencyOn2New\dirs.customProj"
E:\projects\MSBuildTestProjects\projects\sdk\working\DependencyOn2New\1\1.csproj : error : - the reference was not included in the provided input caches
E:\projects\MSBuildTestProjects\projects\sdk\working\DependencyOn2New\1\1.csproj : error : - the reference was called with a target which is not specified in the ProjectReferenceTargets item in "E:\projects\MSBuildTestProjects\projects\sdk\working\DependencyOn2New
\dirs.customProj"
```

### Cause and fix
When a multitargeting node is a root, the outer build dispatches the entry target to all innerbuilds. When it is not a root, the referencing project calls the innerbuilds directly. Thus, on non-root multitargeting projects, the graph re-attaches the innerbuilds to the outerbuild referencing projects. However, this fails when the outer-build referencing project is agnostic of multitargeting nodes (as the case with dirs.proj projects from [Microsoft.Build.Traversal](https://github.com/Microsoft/MSBuildSdks/tree/master/src/Traversal) sdk).

A potential solution is for projects to advertise whether they know how to reference multitargeting projects or not (e.g. via their imported sdk). For projects that do not know how to reference multitargeting projects, the graph should not re-attach the innerbuilds to them and let the outerbuild dispatch to innerbuilds.

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the failure with dirs.proj and 1.csproj using `msbuild dirs.proj /graph /isolate`. Then trace static-graph handling for the non-root multitargeting project and the Microsoft.Build.Traversal case described in the issue. Done means the sample build succeeds without MSB4252 and the graph handles the agnostic outer project correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
build-system
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.