Description
Description
When building a self-contained console application targeting .NET 7, the console application doesn't work with shebang in Linux.
However, when building the same console application targeting .NET 6, the produced console application works fine with shebang.
This causes powershell v7.3.0 to stop working with shebang on Linux. See PowerShell/PowerShell#18510
Reproduction Steps
Build a simple self-contained console application targeting .NET 7
The console application is very simple:
using System;
namespace MyApp
{
internal class Program
{
static void Main(string[] args)
{
for (int i = 0; i < args.Length; i++)
{
Console.WriteLine($"<Arg {i}>: {args[i]}");
}
}
}
}
The .csproj file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>
</Project>
Build a self-contained console application from the C# code, targeting .NET 7:
dotnet publish -r linux-x64 -c Release --self-contained
Create the script file that uses shebang to run the console application
The content of the script file dotnet7
:
#!/home/daxian/apps/1self/bin/Release/net7.0/linux-x64/publish/1self
$true
Then, run chmod
to make the file an executable
chmod +x ./dotnet7
At last, run dotnet7
in bash:
./dotnet7
Expected behavior
The console application should run and print the arguments it receives.
When building against .NET 6, it works as expected, and here is the screenshot of the result:
Actual behavior
When building against .NET 7, it stops working with the following error message:
bash:35> ./dotnet7
The application to execute does not exist: '/home/daxian/temp/1self.dll'.
Regression?
Yes, it's a regression from .NET 6
Known Workarounds
No known workaround so far.
Configuration
Which version of .NET is the code running on?
.NET 7 -- SDK version 7.0.100,
What OS and version, and what distro if applicable?
WSLv2 - Ubuntu 18.04
What is the architecture (x64, x86, ARM, ARM64)?
I reproduced the issue on x64, but didn't try other architectures.
Other information
No response