dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.23k stars 1.35k forks source link

[Bug]: Msbuild crashes when using cache extension with proxy targets pointing to original targets #9117

Open jacdavis opened 1 year ago

jacdavis commented 1 year ago

Issue Description

While implementing build acceleration, I ran into an issue where msbuild is crashing. Csproj passes "Build" and 10 other targets related to scraping the outputgroup data ofr the DTE. These are the additional targets: "BuiltProjectOutputGroup" "BuiltProjectOutputGroupDependencies" "DebugSymbolsProjectOutputGroup" "DebugSymbolsProjectOutputGroupDependencies" "DocumentationProjectOutputGroup" "DocumentationProjectOutputGroupDependencies" "SatelliteDllsProjectOutputGroup" "SatelliteDllsProjectOutputGroupDependencies" "SGenFilesOutputGroup" "SGenFilesOutputGroupDependencies"

In speaking to David Federman, the design is I should be able to return these as proxies to themselves so msbuild will just execute them. However, when I do that, msbuild crashes because they are already added to the build result collection. Callstack is here: Severity Code Description Project File Line Suppression State Error This is an unhandled exception in MSBuild -- PLEASE UPVOTE AN EXISTING ISSUE OR FILE A NEW ONE AT https://aka.ms/msbuild/unhandled

Microsoft.Build.Framework.InternalErrorException: MSB0001: Internal MSBuild Error: Items already exist for target BuiltProjectOutputGroup.

at Microsoft.Build.Shared.ErrorUtilities.ThrowInternalError(String message, Object[] args) at Microsoft.Build.Shared.ErrorUtilities.VerifyThrow(Boolean condition, String unformattedMessage, Object arg0) at Microsoft.Build.Execution.BuildResult.AddResultsForTarget(String target, TargetResult result) at Microsoft.Build.BackEnd.RequestBuilder.g__CopyTargetResultsFromProxyTargetsToRealTargets|68_0(BuildResult resultFromTargetBuilder) at Microsoft.Build.BackEnd.RequestBuilder.d68.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Build.BackEnd.RequestBuilder.d59.MoveNext() ClassLibrary1

Steps to Reproduce

1) Create an msbuild cache extension and invoke that extension from csproj 2) Create a new build result where the proxy targets match the existing targets.

Expected Behavior

This works

Actual Behavior

msbuild crashes

Analysis

See above

Versions & Configurations

No response

dfederm commented 1 year ago

Note to MSBuild team: This is something I should look at

JanKrivanek commented 1 year ago

@dfederm - assigning to you. Please let us know if you'd want any assitance or to hand off the investigation

JanKrivanek commented 1 year ago

https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1906434/