dotnet / dotnet/msbuild

MSBUILDDONOTCATCHTASKEXCEPTIONS still catches the exception

Open
#12,985 0 comments 0 reactions 0 assignees View on GitHub
backlog Priority:3 triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 13h
Merged PRs (30d)
133

Description

### Issue Description

It looks like this environment variable doesn't work completely. The exception is still caught.

### Steps to Reproduce

Set MSBUILDDONOTCATCHTASKEXCEPTIONS =1

Using the project
```xml


Exe
net10.0
enable
enable














if (FailFast)
{
Environment.FailFast(Message);
}
throw new InvalidOperationException(Message);


```

Build this project

### Expected Behavior

Build crashes - with the possibility of creating a dump of the failing task for investigation. Ideally this would be crashing at the point of the task thrown (and not later after catch/rethrow).

### Actual Behavior

Build process does not crash. The exception is caught and the process exits cleanly (no opportunity to capture a dump). Contrast that to the FailFast option shown in the sample for desired behavior.

### Analysis

I noticed that that MSBuild catches and rethrows as a CriticalTaskException.
https://github.com/dotnet/msbuild/blob/dc7f357173d3d795316b86851d95328651592f6d/src/Build/BackEnd/Components/RequestBuilder/TaskBuilder.cs#L827-L835

Then it's later caught, but not rethrown.
https://github.com/dotnet/msbuild/blob/dc7f357173d3d795316b86851d95328651592f6d/src/Build/BackEnd/Components/RequestBuilder/RequestBuilder.cs#L813-L859

I do see an IFDEF for CriticalTaskException -- but this is not active for TASKHOST assembly, so this doesn't get rethrown.
https://github.com/dotnet/msbuild/blob/dc7f357173d3d795316b86851d95328651592f6d/src/Shared/ExceptionHandling.cs#L121-L141

Even so, it'd be much better for dump purposes to halt at the original throw - perhaps by having method indirection that doesn't ever catch/rethrow when MSBUILDDONOTCATCHTASKEXCEPTIONS is set.

### 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.