dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.68k stars 1.06k forks source link

Support `dotnet tool install` from local nuget package file #13429

Closed abdusco closed 6 months ago

abdusco commented 4 years ago

Is there are way to install dotnet tools from nupkg files created by dotnet pack <project>?

I want to quickly install and test my CLI tool but dotnet tool install requires installation from a nuget source.
I can create a local nuget source with nuget add source d:\path\to\nuget\files but a way to directly install nupkg files would be great

>dotnet tool install -g My.Package.1.0.0.nupkg
error NU1101: Unable to find package my.package.cli.1.0.0.nupkg. No packages exist with this id in source(s): dotnet.myget.org roslyn, local, Microsoft Visual Studio Offline Packages, nuget.org
The tool package could not be restored.
Tool 'my.package.1.0.0.nupkg' failed to install. This failure may have been caused by:

* You are attempting to install a preview release and did not use the --version option to specify the version.
* A package by this name was found, but it was not a .NET tool.
* The required NuGet feed cannot be accessed, perhaps because of an Internet connection problem.
* You mistyped the name of the tool.

For more reasons, including package naming enforcement, visit https://aka.ms/failure-installing-tool
>dotnet --list-sdks
3.1.201 [C:\Program Files\dotnet\sdk]
3.1.302 [C:\Program Files\dotnet\sdk]
3.1.401 [C:\Program Files\dotnet\sdk]
5.0.100-preview.7.20366.6 [C:\Program Files\dotnet\sdk]
artemshadrunov commented 4 years ago

I think that you can use: dotnet tool install --global --add-source <path-to-your-nuget-package> <tool-name>

adrien-constant commented 3 years ago

I think that you can use: dotnet tool install --global --add-source <path-to-your-nuget-package> <tool-name>

Just a quick note because I did the mistake, <path-to-your-nuget-package> is the path of the folder, not the nupkg file. File name is loaded from <tool-name>

LeiYangGH commented 3 years ago

Just tried and found that <path-to-your-nuget-package> should be the directory containing .nupkg file, not .nupkg file name itself. Hope it be useful for later users.

copernicus365 commented 3 years ago

To add to what others have said: Unfortunately this can't just specify a path to a .nupkg file, you HAVE to provide the path to a directory in the first argument, meaning <path-to-your-nuget-package> MUST be a directory, and then a name, which MUST repeat the nupkg name (without version, so for microsoft.botsay.1.0.0.nupkg name is microsoft.botsay).

So using their tutorial, if you follow the steps to make the simple little project and finally package the project to produce a .nupkg file (microsoft.botsay.1.0.0.nupkg)... you can then move that nupkg file anywhere, including on another computer. Let's say you had that file living at: "C:\Code\Tools\Botsay\microsoft.botsay.1.0.0.nupkg": to install this as a global tool:

dotnet tool install -g --add-source C:\Code\Tools\Botsay microsoft.botsay

(of course you could have already been in a local folder, so if you were in Tools: `--add-source .\Botsay microsoft.botsay``

YES: It would be terrific if they could update this to install simply with the file path to a .nupkg! That said, it's awesome the main request is already available.

danmastrowcoles commented 3 years ago

In order for me to get this to work inside a Docker image, had to reference the version number of the nuget package. In this example the structure was as follows:

-Dockerfile --tools ---dotnet-trace.3.1.141901.nupkg

To install from the root folder/docker context (after copying it into the context): dotnet tool install --global --add-source ./tools dotnet-trace --version 3.1.141901

BalassaMarton commented 3 years ago

@abdusco take a look at this script we are using for our in-house tool: https://github.com/morganstanley/dotnet-please/blob/main/build-and-install.ps1 NuGetToolsPath is an optional environment variable in case you have restrictions on where executables can be installed.

chen-chao commented 1 year ago

When I specify a local nuget file to --add-source, the error "NU1301: The local source '.nupkg' doesn't exist." is somewhat confusing. It would be better to put a note in the error message, or in the help output beside the --add-source option.

igiona commented 1 year ago

Adding --ignore-failed-sources helped in my case:

dotnet tool update -g MyTool --add-source C:\Package --version 1.6.1-local1 --ignore-failed-sources

JL03-Yue commented 6 months ago

Close as alternative provided

I think that you can use: dotnet tool install --global --add-source <path-to-your-nuget-package> <tool-name>

KalleOlaviNiemitalo commented 6 months ago

Preferably the installation should be done using a nuget.config that prevents the usage of all other sources such as nuget.org. So that the tool is installed from the local file only and there is no risk of installing a like-named malicious package, even if the name has not been reserved.

I set up a build system that creates and publishes both the nupkg and an installer script that creates and uses a temporary nuget.config file. But it would sure be nicer if dotnet tool install itself had an option for this, e.g. --clear-sources, if not direct support for a nupkg file argument.