dotnet / dotnet/msbuild

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

Open
#9,117 3 comments 0 reactions 1 assignee Claimed by @dfederm View on GitHub
bug triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 8h
Merged PRs (30d)
141

Description

### 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.d__68.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.d__59.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_

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.