Skip to content

Nuget restore/package download C# API #10430

@wli3

Description

@wli3

This was raised during development of dotnet tools. The decision was "try to use a temp project and restore the package for now". However, after using this mechanism for 2 years. We still wish to have a C# API to do restore, especially considering we would reuse the dotnet tool install component to install dotnet SDK workloads. Dotnet SDK workloads installation experience needs to be bulletproof or the user will be blocked using Xamarin.

Issues for existing temp project approach

  1. Multiple IO operation and process hops caused unreliability and they are very hard to reproduce and resolve. First a file needs to be written to the disk. And a restore in a separate process need to write more files. The following 2 issues are likely caused by race conditions. However, I cannot reproduce them. The cleanup of the temporary files is also tricky.

    a. .NET 5: Unable to install some .NET tools (dotnet tool install) · Issue #14547 · dotnet/sdk (github.com)

    b. Failed to install tool package ... · Issue #11459 · dotnet/sdk (github.com)

  2. Hard-to-act-on error messages. Because the communication between SDK and nuget restore is via the command line. When error happens, SDK can only redirect the output of nuget and SDK cannot give a more specific guidance for the user to act on. That results the long list of "probably this happened." https://docs.microsoft.com/en-us/dotnet/core/tools/troubleshoot-usage-issues#executable-file-not-found

  3. Environment leak in. Because there is an explicit msbuild run. Environment variables get leaked in. There is no good way to prevent them.

    a. `dotnet tool install ...` fails if environment variable RESTOREPROJECTS is set · Issue #10798 · dotnet/sdk (github.com)

  4. Escape unescaped madness. Because the communication is done via the command line. SDK need to carefully escape/unescape characters. It is not trivial and error prone.

Requirement

It should be a replacement for the temp project. It should select correct TFM and generate asset.json. However, if we can get an API that can simply download package to a specific location, that would fit net6.0 requirement. But it won't help us making tools experience better.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions