dotnet / dotnet/sdk

Make it easy to detect if a .NET app is running as a .NET SDK Tool

Open
#51,336 2 comments 1 reaction 1 assignee Claimed by @dsplaisted View on GitHub
Area-Tools untriaged
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

### Is your feature request related to a problem? Please describe.

It can be helpful as a app author to know if my app is running as a .NET Tool or not, but the SDK doesn't currently give me any signals that this is the case. I can technically see if my app's actual launching binary is `dotnet`, but that only works for local tools or tools run via `dnx` - global tools use apphost shims that don't surface `dotnet` at all.

### Describe the solution you'd like
The CLI should ensure that when tools are run, a marker environment variable is available in the spawned process . This environment variable should be called `DOTNET_TOOL_EXECUTION_MODE` and it should be set to one of the following values:

* `oneshot` when the tool is run via `dnx`, `dotnet tool execute`, or `dotnet dnx` (which are actually all the same mechanism, just with different names for _reasons_)
* `local` when the tool is run via `dotnet ` or `dotnet tool run ` as a local tool
* `global` when the tool is run via `` with it's globally-installed apphost shim, or `dotnet ` when the global shim is named `dotnet-`

This will be easier for `oneshot` and `local` tools, because the CLI owns the spawning of those processes. For global tools, we'll likely have to find a way to embed the env var into the script-or-apphost that's launching the app, and I don't know if that capability exists out of the box with the apphosts that we currently use.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.