-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Description
Description
The enhanced shebang support introduced in .NET 10 Preview 6 works when executing a script without arguments, but fails when the script is executed with arguments.
Reproduction Steps
- Create a C# script file
test.cswith the following content:
#\!/usr/bin/dotnet
Console.WriteLine("Args: " + string.Join(", ", args));-
Make it executable:
chmod +x test.cs -
Execute without arguments (works):
./test.cs
# Output: Args: - Execute with arguments (fails):
./test.cs arg1 arg2
# Error: Could not execute because the specified command or file was not found.
# Possible reasons for this include:
# * You misspelled a built-in dotnet command.
# * You intended to execute a .NET program, but dotnet-./test.cs does not exist.
# * You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.Expected behavior
The script should execute successfully with arguments, similar to how #\!/usr/bin/dotnet run works.
Actual behavior
The script fails with an error suggesting that dotnet is trying to execute dotnet-./test.cs instead of properly handling the shebang.
Configuration
- .NET SDK Version: 10.0.100-preview.6.25358.103
- OS: Linux (WSL2)
- Architecture: x64
Other information
This issue is particularly problematic when scripts are executed through process launchers like CliWrap, which is commonly used in build tools and test frameworks.
The workaround is to use #\!/usr/bin/dotnet run instead, which works correctly with arguments.
Related documentation: https://github.com/dotnet/core/blob/main/release-notes/10.0/preview/preview6/sdk.md#enhanced-shebang-support