Skip to content

[Spec] Warnings and errors in the assets file

Ankit Mishra edited this page May 3, 2017 · 12 revisions

Restore and Build generate duplicate warnings and errors in some scenarios. To improve this restore should log messages to the assets file where they can be de-duplicated with build.

Adding messages to the assets file also improves the scenario where a user builds in a different session, possibly days after doing the restore. If the restore failed build could display the original failure messages from restore to help the user debug the problem.

Reading log messages example

var format = new LockFileFormat();

Log message interface

    public interface IAssetsLogMessage
    {
        /// <summary>
        /// Level to indicate if this is an error or wanring.
        /// </summary>
        LogLevel Level { get; }

        /// <summary>
        /// Indicates the NuGet error code.
        /// </summary>
        NuGetLogCode Code { get; }

        /// <summary>
        /// Indicates the staring generated by the code to go with the error code.
        /// </summary>
        string Message { get; }

        /// <summary>
        /// Indicates the date time at which the error occurred.
        /// </summary>
        DateTimeOffset Time { get; }

        /// <summary>
        /// Indicates the project for which the error was thrown.
        /// </summary>
        string ProjectPath { get; }

        /// <summary>
        /// Level to indicate the warning level for the message.
        /// This is relevant only if the Level == LogLevel.Warning.
        /// </summary>
        WarningLevel WarningLevel { get; }

        /// <summary>
        /// Indicates the file for which the error was thrown.
        /// </summary>
        string FilePath { get; }

        /// <summary>
        /// Indicates the starting line for which the error was thrown.
        /// </summary>
        int StartLineNumber { get; set; }

        /// <summary>
        /// Indicates the starting column for which the error was thrown.
        /// </summary>
        int StartColumnNumber { get; set; }

        /// <summary>
        /// Indicates the ending line for which the error was thrown.
        /// </summary>
        int EndLineNumber { get; set; }

        /// <summary>
        /// Indicates the ending column for which the error was thrown.
        /// </summary>
        int EndColumnNumber { get; set; }

        /// <summary>
        /// Project or Package Id
        /// </summary>
        string LibraryId { get; set; }

        /// <summary>
        /// List of TargetGraphs
        /// </summary>
        IReadOnlyList<string> TargetGraphs { get; set; }
    }

Assets file example

{
  "version": 3,
  "targets": {
    ".NETPlatform,Version=v5.0": {
      "System.Runtime/4.0.20-beta-22927": {
        "type": "package",
        "dependencies": {
          "Frob": "4.0.20"
        },
        "compile": {
          "ref/dotnet/System.Runtime.dll": {}
        }
      }
    }
  },
  "libraries": {
    "System.Runtime/4.0.20-beta-22927": {
      "sha512": "sup3rs3cur3",
      "type": "package",
      "files": [
        "System.Runtime.nuspec"
      ]
    }
  },
  "projectFileDependencyGroups": {
    "": [
      "System.Runtime [4.0.10-beta-*, )"
    ],
    ".NETPlatform,Version=v5.0": []
  },
  "logs": [
    {
      "code": "NU1000",
      "level": "Error",
      "filePath": "kung\\fu\\fighting.targets",
      "startLineNumber": 11,
      "startColumnNumber": 2,
      "endLineNumber": 10,
      "message": "test log message",
      "targetGraph": [
        "net46",
        "netcoreapp1.0",
        "netstandard1.6"
      ]
    }
  ]
}

Contributing

What's Being Worked On?

Check out the proposals in the accepted & proposed folders on the repository, and active PRs for proposals being discussed today.

Common Problems

Clone this wiki locally