NuGet/Home

Improve the "Undefined" value in the Code column of the Error List of Visual Studio to know that a warning comes from NuGet

Open

#14,070 创建于 2025年1月27日

在 GitHub 查看
 (0 评论) (0 反应) (0 负责人)HTML (1,459 star) (292 fork)batch import
Area:ErrorHandlingArea:ProtocolPriority:3Type:DCRhelp wanted

描述

NuGet Product(s) Affected

MSBuild.exe

Current Behavior

Warnings emitted by the "x-nuget-warning" header (specs: https://github.com/NuGet/Home/wiki/%5BSpec%5D-Server-side-warnings-for-NuGet-client) don't have a NuGet code, so the NuGetLogCode.Undefined = 0 value (https://github.com/NuGet/NuGet.Client/blob/dev/src/NuGet.Core/NuGet.Common/Errors/NuGetLogCode.cs) is used and they can appear in the Error List of Visual Studio like so for this example of "No Authorization header detected":

Image

Notice that nothing in the Error List says where this warning comes from. You can spend hours until you discover that they come from a NuGet server (GitHub, in my case).

Desired Behavior

It would be nice that NuGet servers such as GitHub provide a better description (such as "No Authorization header was detected in the request to GitHub") but since that is a server-side issue, there is nothing that you can do. But you can do something about the "Undefined" literal, changing it to "Undefined NuGet code", and therefore at least you know that the error comes from a NuGet operation. I think that it is these lines: https://github.com/dotnet/sdk/blob/63f75ac549d6218da1dd6c459d53e20cbf20459e/src/Tasks/Microsoft.NET.Build.Tasks/LockFileCache.cs#L121C1-L126C49. I think it would be enough to use error code NuGetLogCode.NU1000 (which means "undefined" NuGet error and would appear in the Code column of the Error List as NU1000, and you would know that is a NuGet error) instead of NuGetLogCode.Undefined (which appears in the Code column as "Undefined" and you cannot know that is a NuGet error)

Additional Context

When you use a command-line NuGet client you know that you are executing NuGet commands, but in this case it's Visual Studio who is executing NuGet commands (that don't appear in the Output window) and you don't know. In this case I think Visual Studio is executing the NuGet Audit API because the warning appears just after loading a solution, but I can't know for sure.

贡献者指南