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

Inconsistent argument passing in Environment.GetCommandLineArgs() and Args #749

Open
Pxtl opened this issue Feb 16, 2024 · 0 comments
Open

Comments

@Pxtl
Copy link

Pxtl commented Feb 16, 2024

There are 3 different ways to run the script on Windows:

  1. dotnet script myscript.csx
  2. (after dotnet script register) just run myscript.csx
  3. compile using dotnet script publish myscript.csx and then run myscript.exe

In each of these 3 cases, the Environment.GetCommandLineArgs() contains very different data.

If called using dotnet script then the fully resolved path of the DLL is the first argument, the scriptname is the second.

C:\Users\<username>\.dotnet\tools\.store\dotnet-script\1.5.0\dotnet-script\1.5.0\tools\net8.0\any\dotnet-script.dll;myapp.csx;<user-provided-arguments-start-here>

If called using the registered version, the extra separator argument "--" is added.

C:\Users\<username>\.dotnet\tools\.store\dotnet-script\1.5.0\dotnet-script\1.5.0\tools\net8.0\any\dotnet-script.dll;myapp.csx;--;<user-provided-arguments-start-here>

Finally, if compiled to .exe it behaves a conventional way - first argument is the fully-resolved path to the .exe, all following arguments are the user-provided arguments.

I have not attempted the 4th way (executing a published DLL).

Also, the Args collection is not a good substitute, since that hides all the parameters that are intercepted by dotnet-script whereas they're available in full in Environment.GetCommandLineArgs()

It is very difficult to get a clean collection of arguments to pass onto System.Commandline

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant