dotnet / dotnet/msbuild

Microsoft.Net.Sdk fails with /isolate constraints

Open
#5,687 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 8h
Merged PRs (30d)
141

Description

Root cause copied from https://github.com/dotnet/sdk/issues/13081#issuecomment-681179654:

- https://github.com/dotnet/msbuild/pull/5657 changes the runtime graph (this is the callgraph that emerges as vanilla msbuild does its JIT top down descent) and makes it different from the inferred static graph. Up until now, an outer build only called into its inner builds when it was a top level entry point project. When the outerbuild was not a root, it never called in its innerbuilds (instead the projects referring to the outer build called its inner builds). After this PR an outer build always calls its innerbuilds with GetTargetFrameworksWithPlatformForSingleTargetFramework, regardless if it’s a root node or not. This breaks [an assumption that static graph makes](https://github.com/dotnet/msbuild/blob/2a712c6eff80fce71bc4114fdc35754178cbfbd4/src/Build/Graph/ProjectInterpretation.cs#L132-L139) about how outer builds interact with inner builds.
- Execution timeline:
- The undeclared inner builds get scheduled to run before the static graph schedules its own ProjectInstances for those same innerbuilds.
- When static graph schedules its own project instances for those inner builds they conflict in the BuildManager’s ConfigCache with the project instances from the undeclared inner builds
- This conflict [incorrectly triggers](https://github.com/dotnet/msbuild/blob/master/src/Build/BackEnd/BuildManager/BuildManager.cs#L1708-L1718) a project instance conflict resolution strategy that was put there as a workaround for a CPS-MSBuild bug.
- The resolution strategy adds a global property containing a GUID into the static graph’s project instances
- This GUID eventually causes a cache miss which triggers the /isolate error
- Things that contribute to this:
- Projects calling into themselves with different global properties are exempt from /isolate constraints. Had this not been the case, /isolate would have failed earlier with a more relevant error message

The ideal fix should be to change static graph to support adding explicit edges and nodes for the undeclared inner builds introduced in #5657.
Removing the relaxation that projects are exempt from isolation constraints when calling into themselves with different global properties would also make isolation failures caused by these scenarios easier to investigate.

Once this is fixed, isolation tests need to be reenabled in the sdk: https://github.com/dotnet/sdk/issues/13081

Repro zip:
[repro.zip](https://github.com/dotnet/msbuild/files/5138326/repro.zip)

Zip also contains two binlogs: a successful isolation build before #5657, and a failing one after #5657

Commands to expose the failure:
```
dotnet restore 1\1.csproj

...

dotnet msbuild 1\1.csproj /graph /isolate

...

e:\projects\sdk\artifacts\bin\redist\Debug\dotnet\sdk\5.0.100-dev\Microsoft.Common.CurrentVersion.targets(1844,5): error : MSB4252: Project "e:\delete\play\2\2.csproj" with global properties [e:\delete\play\2\2.csproj]
e:\projects\sdk\artifacts\bin\redist\Debug\dotnet\sdk\5.0.100-dev\Microsoft.Common.CurrentVersion.targets(1844,5): error : (IsGraphBuild=true) [e:\delete\play\2\2.csproj]
e:\projects\sdk\artifacts\bin\redist\Debug\dotnet\sdk\5.0.100-dev\Microsoft.Common.CurrentVersion.targets(1844,5): error : is building project "e:\delete\play\4\4.csproj" with global properties [e:\delete\play\2\2.csproj]
e:\projects\sdk\artifacts\bin\redist\Debug\dotnet\sdk\5.0.100-dev\Microsoft.Common.CurrentVersion.targets(1844,5): error : (IsGraphBuild=true; TargetFramework=netstandard1.3) [e:\delete\play\2\2.csproj]
e:\projects\sdk\artifacts\bin\redist\Debug\dotnet\sdk\5.0.100-dev\Microsoft.Common.CurrentVersion.targets(1844,5): error : with the (default) target(s) but the build result for the built project is not in the engine cache. In isolated builds this could mean one of the following: [e:\delete\play\2\2.csproj]
e:\projects\sdk\artifacts\bin\redist\Debug\dotnet\sdk\5.0.100-dev\Microsoft.Common.CurrentVersion.targets(1844,5): error : - the reference was called with a target which is not specified in the ProjectReferenceTargets item in project "e:\delete\play\2\2.csproj" [e:\delete\play\2\2.csproj]
e:\projects\sdk\artifacts\bin\redist\Debug\dotnet\sdk\5.0.100-dev\Microsoft.Common.CurrentVersion.targets(1844,5): error : - the reference was called with global properties that do not match the static graph inferred nodes [e:\delete\play\2\2.csproj]
e:\projects\sdk\artifacts\bin\redist\Debug\dotnet\sdk\5.0.100-dev\Microsoft.Common.CurrentVersion.targets(1844,5): error : - the reference was not explicitly specified as a ProjectReference item in project "e:\delete\play\2\2.csproj" [e:\delete\play\2\2.csproj]
e:\projects\sdk\artifacts\bin\redist\Debug\dotnet\sdk\5.0.100-dev\Microsoft.Common.CurrentVersion.targets(1844,5): error : [e:\delete\play\2\2.csproj]
e:\projects\sdk\artifacts\bin\redist\Debug\dotnet\sdk\5.0.100-dev\Microsoft.Common.CurrentVersion.targets(1844,5): error : MSB4252: Project "e:\delete\play\3\3.csproj" with global properties [e:\delete\play\3\3.csproj]
e:\projects\sdk\artifacts\bin\redist\Debug\dotnet\sdk\5.0.100-dev\Microsoft.Common.CurrentVersion.targets(1844,5): error : (IsGraphBuild=true; TargetFramework=net462; MSBuildProjectInstance71f975b1617d4a96854a1c6c18b030bc=Forces unique project identity in the MSBuild engine) [e:\delete\play\3\3.csproj]
e:\projects\sdk\artifacts\bin\redist\Debug\dotnet\sdk\5.0.100-dev\Microsoft.Common.CurrentVersion.targets(1844,5): error : is building project "e:\delete\play\4\4.csproj" with global properties [e:\delete\play\3\3.csproj]
e:\projects\sdk\artifacts\bin\redist\Debug\dotnet\sdk\5.0.100-dev\Microsoft.Common.CurrentVersion.targets(1844,5): error : (IsGraphBuild=true; TargetFramework=net461) [e:\delete\play\3\3.csproj]
e:\projects\sdk\artifacts\bin\redist\Debug\dotnet\sdk\5.0.100-dev\Microsoft.Common.CurrentVersion.targets(1844,5): error : with the (default) target(s) but the build result for the built project is not in the engine cache. In isolated builds this could mean one of the following: [e:\delete\play\3\3.csproj]
e:\projects\sdk\artifacts\bin\redist\Debug\dotnet\sdk\5.0.100-dev\Microsoft.Common.CurrentVersion.targets(1844,5): error : - the reference was called with a target which is not specified in the ProjectReferenceTargets item in project "e:\delete\play\3\3.csproj" [e:\delete\play\3\3.csproj]
e:\projects\sdk\artifacts\bin\redist\Debug\dotnet\sdk\5.0.100-dev\Microsoft.Common.CurrentVersion.targets(1844,5): error : - the reference was called with global properties that do not match the static graph inferred nodes [e:\delete\play\3\3.csproj]
e:\projects\sdk\artifacts\bin\redist\Debug\dotnet\sdk\5.0.100-dev\Microsoft.Common.CurrentVersion.targets(1844,5): error : - the reference was not explicitly specified as a ProjectReference item in project "e:\delete\play\3\3.csproj" [e:\delete\play\3\3.csproj]
e:\projects\sdk\artifacts\bin\redist\Debug\dotnet\sdk\5.0.100-dev\Microsoft.Common.CurrentVersion.targets(1844,5): error : [e:\delete\play\3\3.csproj]
e:\projects\sdk\artifacts\bin\redist\Debug\dotnet\sdk\5.0.100-dev\Microsoft.Common.CurrentVersion.targets(1844,5): error : MSB4252: Project "e:\delete\play\3\3.csproj" with global properties [e:\delete\play\3\3.csproj]
e:\projects\sdk\artifacts\bin\redist\Debug\dotnet\sdk\5.0.100-dev\Microsoft.Common.CurrentVersion.targets(1844,5): error : (IsGraphBuild=true; TargetFramework=netstandard2.0) [e:\delete\play\3\3.csproj]
e:\projects\sdk\artifacts\bin\redist\Debug\dotnet\sdk\5.0.100-dev\Microsoft.Common.CurrentVersion.targets(1844,5): error : is building project "e:\delete\play\4\4.csproj" with global properties [e:\delete\play\3\3.csproj]
e:\projects\sdk\artifacts\bin\redist\Debug\dotnet\sdk\5.0.100-dev\Microsoft.Common.CurrentVersion.targets(1844,5): error : (IsGraphBuild=true; TargetFramework=netstandard1.6) [e:\delete\play\3\3.csproj]
e:\projects\sdk\artifacts\bin\redist\Debug\dotnet\sdk\5.0.100-dev\Microsoft.Common.CurrentVersion.targets(1844,5): error : with the (default) target(s) but the build result for the built project is not in the engine cache. In isolated builds this could mean one of the following: [e:\delete\play\3\3.csproj]
e:\projects\sdk\artifacts\bin\redist\Debug\dotnet\sdk\5.0.100-dev\Microsoft.Common.CurrentVersion.targets(1844,5): error : - the reference was called with a target which is not specified in the ProjectReferenceTargets item in project "e:\delete\play\3\3.csproj" [e:\delete\play\3\3.csproj]
e:\projects\sdk\artifacts\bin\redist\Debug\dotnet\sdk\5.0.100-dev\Microsoft.Common.CurrentVersion.targets(1844,5): error : - the reference was called with global properties that do not match the static graph inferred nodes [e:\delete\play\3\3.csproj]
e:\projects\sdk\artifacts\bin\redist\Debug\dotnet\sdk\5.0.100-dev\Microsoft.Common.CurrentVersion.targets(1844,5): error : - the reference was not explicitly specified as a ProjectReference item in project "e:\delete\play\3\3.csproj" [e:\delete\play\3\3.csproj]
e:\projects\sdk\artifacts\bin\redist\Debug\dotnet\sdk\5.0.100-dev\Microsoft.Common.CurrentVersion.targets(1844,5): error : [e:\delete\play\3\3.csproj]
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.