Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document dotnet tools plugin usage #3379

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion docs/reference/extensibility/NuGet-Cross-Platform-Plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ CI/CD scenarios and power users can use environment variables to override the be

- `NUGET_NETFX_PLUGIN_PATHS` - defines the plugins that will be used by the .NET Framework based tooling (NuGet.exe/MSBuild.exe/Visual Studio). Takes precedence over `NUGET_PLUGIN_PATHS`. (NuGet version 5.3+ only)
- `NUGET_NETCORE_PLUGIN_PATHS` - defines the plugins that will be used by the .NET Core based tooling (dotnet.exe). Takes precedence over `NUGET_PLUGIN_PATHS`. (NuGet version 5.3+ only)
- `NUGET_PLUGIN_PATHS` - defines the plugins that will be used for that NuGet process, priority preserved. If this environment variable is set, it overrides the convention based discovery. Ignored if either of the framework specific variables is specified.
- `NUGET_PLUGIN_PATHS`
- defines the plugins that will be used for that NuGet process, priority preserved. If this environment variable is set, it overrides the convention based discovery. Ignored if either of the framework specific variables is specified.

- Starting 6.13, this can also be used to specify a path to a .Net tools plugin path.
- User-location, the NuGet Home location in `%UserProfile%/.nuget/plugins`. This location cannot be overriden. A different root directory will be used for .NET Core and .NET Framework plugins.

| Framework | Root discovery location |
Expand Down Expand Up @@ -99,6 +102,48 @@ The plugin entry point will be the name of the installed folder, with the .dll e
> [!Note]
> There is currently no user story for the installation of the plugins. It's as simple as moving the required files into the predetermined location.

### Support for Plugins Installed as .NET Tools

Starting 6.13, NuGet now supports plugins installed as global .NET tools. This enables plugin authors to publish their plugins as .NET tools, simplifying the deployment process.

#### Key Features

1. Plugins installed as .NET tools must follow a naming convention: **`nuget-plugin-*`**.
2. Upon installation, these plugins are added to the `PATH` by the .NET SDK. NuGet scans the `PATH` environment variable for executables with names starting with `nuget-plugin-`.
3. On Windows, NuGet looks for `.exe` or `.bat` files, while on Linux and macOS, it identifies plugins by checking for the executable bit.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this in addition to #1?

So how does one ship a global tool that works on both linux & windows?

4. These plugins are launched in a separate process, consistent with the existing design.

#### Example Workflow

**For Plugin Authors:**

1. Add the following property to the plugin project:

```xml
<PropertyGroup>
<PackAsTool>true</PackAsTool>
<ToolCommandName>nuget-plugin-myplugin</ToolCommandName>
</PropertyGroup>
```

2. Publish the plugin as a .NET tool using `dotnet pack`.

**For Consumers:**

1. Install the plugin using:

```bash
dotnet tool install -g nuget-plugin-myplugin
```

2. Use the plugin seamlessly in scenarios requiring NuGet authentication or operations like `dotnet restore --interactive`.

> **Note:** Plugins installed as .NET tools provide a consistent experience across .NET Core and .NET Framework, eliminating the need to maintain separate plugins for each framework.

### Security Considerations

.NET tools run in full trust. It is essential to install only trusted plugins. While this is not a new concern, users should be aware of the risks when installing NuGet plugins via .NET tools.

## Supported operations

Two operations are supported under the new plugin protocol.
Expand Down