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

Unable to use [env:key=value] directive with 8.0.100 #37686

Closed
xt0rted opened this issue Dec 29, 2023 · 5 comments
Closed

Unable to use [env:key=value] directive with 8.0.100 #37686

xt0rted opened this issue Dec 29, 2023 · 5 comments
Assignees
Labels
Area-CLI untriaged Request triage from a team member

Comments

@xt0rted
Copy link
Contributor

xt0rted commented Dec 29, 2023

Describe the bug

In versions of the sdk prior to 8.0.100 I was able to pass env vars by doing dotnet watch [env:DOTNET_WATCH_RESTART_ON_RUDE_EDIT=true] ... but after updating to 8.0.100 I now get the following error:

dotnet watch [env:DOTNET_WATCH_RESTART_ON_RUDE_EDIT=true] --verbose --project sample

Unrecognized command or argument '[env:DOTNET_WATCH_RESTART_ON_RUDE_EDIT=true]'.

To Reproduce

  1. Clone this repo https://github.com/xt0rted/heroicons-tag-helper/tree/fb2943296bcc0ac35b7b3689a6be74415a8ef8ba
  2. Run the following
    npm ci
    dotnet tool restore
    dotnet r watch
    
  3. The site should load
  4. Stop watching
  5. Update the global.json to use 8.0.100
  6. Try to run dotnet r watch again and you should get the above error

You can skip the dotnet tool bit and run dotnet watch directly, happens either way.

Exceptions (if any)

Details
Unrecognized command or argument '[env:DOTNET_WATCH_RESTART_ON_RUDE_EDIT=true]'.

Description:

Environment variables:

DOTNET_USE_POLLING_FILE_WATCHER
When set to '1' or 'true', dotnet-watch will poll the file system for
changes. This is required for some file systems, such as network shares,
Docker mounted volumes, and other virtual file systems.

DOTNET_WATCH
dotnet-watch sets this variable to '1' on all child processes launched.

DOTNET_WATCH_ITERATION
dotnet-watch sets this variable to '1' and increments by one each time
a file is changed and the command is restarted.

DOTNET_WATCH_SUPPRESS_EMOJIS
When set to '1' or 'true', dotnet-watch will not show emojis in the
console output.

Remarks:
The special option '--' is used to delimit the end of the options and
the beginning of arguments that will be passed to the child dotnet process.

For example: dotnet watch -- --verbose run

Even though '--verbose' is an option dotnet-watch supports, the use of '--'
indicates that '--verbose' should be treated instead as an argument for
dotnet-run.

Examples:
dotnet watch run
dotnet watch test

Usage:
dotnet-watch [...] [options]

--no-launch-profile Do not attempt to use launchSettings.json to configure the application.
-f, --framework The target framework to run for. The target framework must also be specified in the project file.
--property Properties to be passed to MSBuild.
--list Lists all discovered files without starting the watcher.

Further technical details

  • Include the output of dotnet --info
Details
dotnet --info     
.NET SDK:
 Version:           8.0.100
 Commit:            57efcf1350
 Workload version:  8.0.100-manifests.8d38d0cc

Runtime Environment:
OS Name: Windows
OS Version: 10.0.22621
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\8.0.100\

.NET workloads installed:
Workload version: 8.0.100-manifests.8d38d0cc
There are no installed workloads to display.

Host:
Version: 8.0.0
Architecture: x64
Commit: 5535e31a71

.NET SDKs installed:
7.0.417 [C:\Program Files\dotnet\sdk]
8.0.114 [C:\Program Files\dotnet\sdk]
7.0.203 [C:\Program Files\dotnet\sdk]
7.0.311 [C:\Program Files\dotnet\sdk]
7.0.404 [C:\Program Files\dotnet\sdk]
9.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.25 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.25 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.25 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
Not set

global.json file:
C:\dev\xt0rted\azure-supercloud\global.json

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download

  • The IDE (VS / VS Code/ VS4Mac) you're running on, and its version

None, running via cli in windows terminal

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Watch untriaged Request triage from a team member labels Dec 29, 2023
@baronfel
Copy link
Member

baronfel commented Jan 8, 2024

@jonsequitur did the env var directive get removed/obsoleted from S.CL? If so we may consider adding it back ourselves.

@xt0rted are you able to use shell-specific env-var setting techniques to workaround this?

@xt0rted
Copy link
Contributor Author

xt0rted commented Jan 8, 2024

@baronfel I've been using the cli with another dotnet tool which also uses System.CommandLine (the most recent nuget version, not the DevOps feed like this repo is using) and that also has support for the env directive. So in some cases I was able to move the parameters around and have it still work. Depending on how I'm calling dotnet ... the only option is a shell specific way but I've avoided that for now because of how verbose it is over my current scripts.

When I was working on my tools I found I always had to opt-in to this directive like so:

var parser = new CommandLineBuilder(rootCommand)
    .UseEnvironmentVariableDirective()
    // ...
    ;

I've looked through the v7 sdk code and couldn't find where that was happening so I'm not sure how the cli used to wire this up.

With the latest version of System.CommandLine it looks to be wired up slightly different now by including new EnvironmentVariablesDirective() in Parser.cs.

@baronfel
Copy link
Member

baronfel commented Jan 9, 2024

Good spot! I've added it back in #37827, we'll get it approved and merged.

@marcpopMSFT marcpopMSFT self-assigned this Jan 12, 2024
@marcpopMSFT
Copy link
Member

Approved and merged for release in Feb. Closing.

@xt0rted
Copy link
Contributor Author

xt0rted commented Feb 14, 2024

I just updated to 8.0.200 and I'm still unable to run dotnet watch [env:DOTNET_WATCH_RESTART_ON_RUDE_EDIT=true] --verbose like I can in v7 and lower. Unless I'm mistaken this update was included in this release.

Here's the full output for a .net 7 web app using both the 7.0.406 and 8.0.200 sdks.

7.0.406

dotnet --info
❯ dotnet --info
.NET SDK:
 Version:   7.0.406
 Commit:    cf888f0acf

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22621
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\7.0.406\

Host:
  Version:      8.0.2
  Architecture: x64
  Commit:       1381d5ebd2

.NET SDKs installed:
  6.0.419 [C:\Program Files\dotnet\sdk]
  7.0.116 [C:\Program Files\dotnet\sdk]
  7.0.203 [C:\Program Files\dotnet\sdk]
  7.0.313 [C:\Program Files\dotnet\sdk]
  7.0.406 [C:\Program Files\dotnet\sdk]
  8.0.102 [C:\Program Files\dotnet\sdk]
  8.0.200 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.27 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.27 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.27 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  C:\Users\brian\source\repos\WebApplication16\WebApplication16\global.json

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download
dotnet watch [env:DOTNET_WATCH_RESTART_ON_RUDE_EDIT=true] --verbose
❯ dotnet watch [env:DOTNET_WATCH_RESTART_ON_RUDE_EDIT=true] --verbose
dotnet watch ⌚ Project supports hot reload and was configured to run with the default run-command. Watching with hot-reload
dotnet watch ⌚ DOTNET_WATCH_RESTART_ON_RUDE_EDIT = 'true'. Restarting without prompt.

8.0.200

dotnet --info
❯ dotnet --info
.NET SDK:
 Version:           8.0.200
 Commit:            438cab6a9d
 Workload version:  8.0.200-manifests.e575128c

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22621
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\8.0.200\

.NET workloads installed:
There are no installed workloads to display.

Host:
  Version:      8.0.2
  Architecture: x64
  Commit:       1381d5ebd2

.NET SDKs installed:
  6.0.419 [C:\Program Files\dotnet\sdk]
  7.0.116 [C:\Program Files\dotnet\sdk]
  7.0.203 [C:\Program Files\dotnet\sdk]
  7.0.313 [C:\Program Files\dotnet\sdk]
  7.0.406 [C:\Program Files\dotnet\sdk]
  8.0.102 [C:\Program Files\dotnet\sdk]
  8.0.200 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.27 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.27 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.27 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  C:\Users\brian\source\repos\WebApplication16\WebApplication16\global.json

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download
dotnet watch [env:DOTNET_WATCH_RESTART_ON_RUDE_EDIT=true] --verbose
❯ dotnet watch [env:DOTNET_WATCH_RESTART_ON_RUDE_EDIT=true] --verbose
Unrecognized command or argument '[env:DOTNET_WATCH_RESTART_ON_RUDE_EDIT=true]'.

Description:

  Environment variables:

    DOTNET_USE_POLLING_FILE_WATCHER
    When set to '1' or 'true', dotnet-watch will poll the file system for
    changes. This is required for some file systems, such as network shares,
    Docker mounted volumes, and other virtual file systems.

    DOTNET_WATCH
    dotnet-watch sets this variable to '1' on all child processes launched.

    DOTNET_WATCH_ITERATION
    dotnet-watch sets this variable to '1' and increments by one each time
    a file is changed and the command is restarted.

    DOTNET_WATCH_SUPPRESS_EMOJIS
    When set to '1' or 'true', dotnet-watch will not show emojis in the
    console output.

  Remarks:
    The special option '--' is used to delimit the end of the options and
    the beginning of arguments that will be passed to the child dotnet process.

    For example: dotnet watch -- --verbose run

    Even though '--verbose' is an option dotnet-watch supports, the use of '--'
    indicates that '--verbose' should be treated instead as an argument for
    dotnet-run.

  Examples:
    dotnet watch run
    dotnet watch test


Usage:
  dotnet-watch [<remainingCommandArgs>...] [options]

Arguments:
  <remainingCommandArgs>

Options:
  -?, -h, --help         Show help and usage information
  --version              Show version information
  -q, --quiet            Suppresses all output except warnings and errors
  -v, --verbose          Show verbose output
  --no-hot-reload        Suppress hot reload for supported apps.
  --non-interactive      Runs dotnet-watch in non-interactive mode. This option is only supported when running with Hot
                         Reload enabled. Use this option to prevent console input from being captured.
  --project              The project to watch
  -lp, --launch-profile  The launch profile to start the project with (case-sensitive).
  --no-launch-profile    Do not attempt to use launchSettings.json to configure the application.
  -f, --framework        The target framework to run for. The target framework must also be specified in the project
                         file.
  --property             Properties to be passed to MSBuild.
  --list                 Lists all discovered files without starting the watcher.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-CLI untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

3 participants