dotnet / dotnet/msbuild

Allow SDK Resolvers to specify file information for generated warnings

Open
#8,199 0 comments 0 reactions 0 assignees View on GitHub
backlog triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 8h
Merged PRs (30d)
141

Description

## Problem Description

SDK Resolvers are allowed to return SdkResult structures which capture information about the resolution process, including the path to the resolved SDK, errors, and warnings.

Currently, these errors and warnings are limited to string values and pinned to the Project file that caused the SDK to be loaded, which means that when users view these errors or warnings, they get a link to a file that may not be strictly useful. For example, here are some warnings reported by the .NET SDK Resolver:

```
Severity Code Description Project File Line Suppression State
Warning Unable to locate the .NET SDK version '6.0.402' as specified by global.json, please check that the specified version is installed. BLAH 7
Warning Unable to locate the .NET SDK version '6.0.402' as specified by global.json, please check that the specified version is installed. BLAH 154
Warning Unable to locate the .NET SDK version '6.0.402' as specified by global.json, please check that the specified version is installed. BLAH 155
```

These warnings should be able to point specifically to the global.json file in question, but are not able to due to this string-based limitation.

## Proposal

The [SdkResult type](https://github.dev/dotnet/msbuild/blob/d797c48da13aaa4dc7ae440ed7603c990cd44317/src/Build/BackEnd/Components/SdkResolution/SdkResolverService.cs#L375-L386) should change to represent warnings and errors as lists of structures that allow specifying file and line location information, similar to other MSBuild-provided diagnostics, and the user-facing ways to construct instances of this type [in SdkResultFactory](https://github.dev/dotnet/msbuild/blob/d797c48da13aaa4dc7ae440ed7603c990cd44317/src/Build/BackEnd/Components/SdkResolution/SdkResolverService.cs#L375-L386) should add overloads that allow providing these structures directly. This would allow resolvers to create diagnostics that point directly at the source of their problems.

Once these structures were available, the [LogWarnings helper in the SdkResolverService](https://github.dev/dotnet/msbuild/blob/d797c48da13aaa4dc7ae440ed7603c990cd44317/src/Build/BackEnd/Components/SdkResolution/SdkResolverService.cs#L375-L386) would change to use the file/line information from the Warnings and Errors of the SdkResult, instead of using the currently-evaluating project file.

## Follow-up tasks

* [ ] The .NET SDK resolver should add this file information [here](https://github.com/dotnet/sdk/blob/c4c98a346c90b8ad08cd25df8bcbf68e1ae36472/src/Resolvers/Microsoft.DotNet.MSBuildSdkResolver/MSBuildSdkResolver.cs#L157)

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.