dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.66k stars 1.06k forks source link

The .NET 8.0 SDK can't run built binary with `./Test`, but works with `dotnet ./Test.dll` #36985

Open Anduin2017 opened 10 months ago

Anduin2017 commented 10 months ago

Describe the bug

After installing the 8.0 SDK in Ubuntu 22.04, can't run the binary generated.

./Test # Failed
dotnet ./Test.dll # works
dotnet run # works

To Reproduce

Install .NET SDK 8 in Ubuntu, following the official document:

I tried both ways:

wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh
chmod +x ./dotnet-install.sh
./dotnet-install.sh --version latest --runtime aspnetcore

image

declare repo_version=$(if command -v lsb_release &> /dev/null; then lsb_release -r -s; else grep -oP '(?<=^VERSION_ID=).+' /etc/os-release | tr -d '"'; fi)
wget https://packages.microsoft.com/config/ubuntu/$repo_version/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb
sudo apt update
sudo apt install dotnet-sdk-8.0 dotnet-runtime-8.0

image

After installing, everything seems fine:

image

But if you build a console app:

mkdir Test
cd Test
dotnet new console
dotnet publish -c Release
cd ./bin/Release/net8.0/publish
./Test

It will crash:

image

anduin@lab:~/Test/bin/Release/net8.0/publish$ ls -ashl
total 172K
4.0K drwxr-xr-x 2 anduin anduin 4.0K Nov 17 05:59 .
4.0K drwxr-xr-x 3 anduin anduin 4.0K Nov 17 05:47 ..
 64K -rwxr-xr-x 1 anduin anduin  61K Nov 17 01:24 dotnet-install.sh
 72K -rwxr-xr-x 1 anduin anduin  71K Nov 17 05:47 Test
4.0K -rw-r--r-- 1 anduin anduin  382 Nov 17 05:47 Test.deps.json
8.0K -rw-r--r-- 1 anduin anduin 4.5K Nov 17 05:47 Test.dll
 12K -rw-r--r-- 1 anduin anduin  11K Nov 17 05:47 Test.pdb
4.0K -rw-r--r-- 1 anduin anduin  328 Nov 17 05:48 Test.runtimeconfig.json
anduin@lab:~/Test/bin/Release/net8.0/publish$ ./Test 
You must install .NET to run this application.

App: /home/anduin/Test/bin/Release/net8.0/publish/Test
Architecture: x64
App host version: 8.0.0
.NET location: Not found

Learn more:
https://aka.ms/dotnet/app-launch-failed

Download the .NET runtime:
https://aka.ms/dotnet-core-applaunch?missing_runtime=true&arch=x64&rid=linux-x64&os=ubuntu.22.04&apphost_version=8.0.0
anduin@lab:~/Test/bin/Release/net8.0/publish$ 

Exceptions (if any)

anduin@lab:~/Test/bin/Release/net8.0/publish$ ./Test 
You must install .NET to run this application.

App: /home/anduin/Test/bin/Release/net8.0/publish/Test
Architecture: x64
App host version: 8.0.0
.NET location: Not found

Further technical details

Mentioned above.

Anduin2017 commented 10 months ago

Rebooting doesn't help.

Anduin2017 commented 8 months ago

General ping. This issue is still blocking us upgrading from 7 to 8.

EdiWang commented 8 months ago

Same issue here. I installed .NET 8 SDK on Ubuntu 22.04 using this method:

sudo dpkg --purge packages-microsoft-prod && sudo dpkg -i packages-microsoft-prod.deb
sudo apt-get update

sudo apt-get install -y gpg
wget -O - https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor -o microsoft.asc.gpg
sudo mv microsoft.asc.gpg /etc/apt/trusted.gpg.d/
wget https://packages.microsoft.com/config/ubuntu/22.04/prod.list
sudo mv prod.list /etc/apt/sources.list.d/microsoft-prod.list
sudo chown root:root /etc/apt/trusted.gpg.d/microsoft.asc.gpg
sudo chown root:root /etc/apt/sources.list.d/microsoft-prod.list
sudo apt-get update && sudo apt-get install -y dotnet-sdk-8.0

image

baronfel commented 8 months ago

Can you all follow the steps described in the Corehost tracing docs to log how the app is trying to discover/load the runtime? That would help us identify where the gap is coming from. This works on both 7.0 and 8.0, so if you had examples of these traces from apps built with either SDK that would help.

EdiWang commented 8 months ago

Hi @baronfel

The output log is:

edi@edi-virtual-machine:~/curry$ ls
bin  curry.csproj  curry.sln  obj  Program.cs
edi@edi-virtual-machine:~/curry$ cd bin/Release/net8.0/publish/
edi@edi-virtual-machine:~/curry/bin/Release/net8.0/publish$ ls
curry  curry.deps.json  curry.dll  curry.pdb  curry.runtimeconfig.json
edi@edi-virtual-machine:~/curry/bin/Release/net8.0/publish$ ./curry 
Tracing enabled @ Fri Dec 29 04:59:54 2023 GMT
--- Invoked apphost [version: 8.0.0 @Commit: 5535e31a712343a63f5d7d796cd874e563e5ac14] main = {
./curry
}
The managed DLL bound to this executable is: 'curry.dll'
Using environment variable DOTNET_ROOT=[/home/edi/.dotnet] as runtime location.
Looking for architecture-specific install_location file in '/etc/dotnet/install_location_x64'.
The install_location file ['/etc/dotnet/install_location_x64'] does not exist - skipping.
Looking for install_location file in '/etc/dotnet/install_location'.
The install_location file ['/etc/dotnet/install_location'] does not exist - skipping.
The required library libhostfxr.so could not be found. Searched with root path [/home/edi/curry/bin/Release/net8.0/publish/], environment variable [DOTNET_ROOT], default install location [/usr/share/dotnet], self-registered config location [/etc/dotnet/install_location_x64]
You must install .NET to run this application.

App: /home/edi/curry/bin/Release/net8.0/publish/curry
Architecture: x64
App host version: 8.0.0
.NET location: Not found

Learn more:
https://aka.ms/dotnet/app-launch-failed

Download the .NET runtime:
https://aka.ms/dotnet-core-applaunch?missing_runtime=true&arch=x64&rid=linux-x64&os=ubuntu.22.04&apphost_version=8.0.0
baronfel commented 8 months ago

@EdiWang is this with a standard, package-based installation? can you include the output from dotnet --info? I suspect that your installation is not quite correct because the packages should create those install_location files. Note that installing .NET from the Microsoft packages requires more than you've shown in your comment - you must also tell apt to ignore the distro feeds for the .NET packages, because .NET is available from Canonical as well. Details for doing this can be found here.

EdiWang commented 8 months ago

The command I used to install .NET 8 SDK is actually from the official document here

Previous to this step. I've tried Scripted install. However, that did not even give me the $HOME/.dotnet directory, this is why I tried my second option.

I believe I am installing .NET from Microsoft package source.

My dotnet --info output (without corehost trace):

edi@edi-virtual-machine:~$ dotnet --info
.NET SDK:
 Version:           8.0.100
 Commit:            57efcf1350
 Workload version:  8.0.100-manifests.6c33ef20

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  22.04
 OS Platform: Linux
 RID:         linux-x64
 Base Path:   /usr/share/dotnet/sdk/8.0.100/

.NET workloads installed:
 Workload version: 8.0.100-manifests.6c33ef20
There are no installed workloads to display.

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

.NET SDKs installed:
  8.0.100 [/usr/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 8.0.0 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 8.0.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  DOTNET_ROOT       [/home/edi/.dotnet]

global.json file:
  Not found

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

Download .NET:
  https://aka.ms/dotnet/download
baronfel commented 8 months ago

The DOTNET_ROOT from the scripted installation is corrupting your installation. Unset that env var and you should be good to go.

EdiWang commented 8 months ago

Thanks @baronfel

I removed DOTNET_ROOT, the Linux executable works fine now!

edi@edi-virtual-machine:~/curry/bin/Release/net8.0/publish$ ./curry
Hello
Anduin2017 commented 8 months ago

Hi, @baronfel

My situation seems to be different:

anduin@lab:~/Console/bin/Release/net8.0/publish$ dotnet --info
.NET SDK:
 Version:           8.0.100
 Commit:            57efcf1350
 Workload version:  8.0.100-manifests.6c33ef20

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  22.04
 OS Platform: Linux
 RID:         linux-x64
 Base Path:   /usr/share/dotnet/sdk/8.0.100/

.NET workloads installed:
 Workload version: 8.0.100-manifests.6c33ef20
There are no installed workloads to display.

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

.NET SDKs installed:
  8.0.100 [/usr/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 8.0.0 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 8.0.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  Not found

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

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

anduin@lab:~/Console/bin/Release/net8.0/publish$ ./Console 
Tracing enabled @ Fri Dec 29 06:06:02 2023 GMT
--- Invoked apphost [version: 8.0.0 @Commit: 5535e31a712343a63f5d7d796cd874e563e5ac14] main = {
./Console
}
The managed DLL bound to this executable is: 'Console.dll'
Looking for architecture-specific install_location file in '/etc/dotnet/install_location_x64'.
Found registered install location '/usr/lib/dotnet'.
Using global installation location [/usr/lib/dotnet] as runtime location.
The required library libhostfxr.so could not be found. Searched with root path [/home/anduin/Console/bin/Release/net8.0/publish/], environment variable [DOTNET_ROOT], default install location [/usr/lib/dotnet], self-registered config location [/etc/dotnet/install_location_x64]
You must install .NET to run this application.

App: /home/anduin/Console/bin/Release/net8.0/publish/Console
Architecture: x64
App host version: 8.0.0
.NET location: Not found

Learn more:
https://aka.ms/dotnet/app-launch-failed

Download the .NET runtime:
https://aka.ms/dotnet-core-applaunch?missing_runtime=true&arch=x64&rid=linux-x64&os=ubuntu.22.04&apphost_version=8.0.0
baronfel commented 8 months ago

@Anduin2017 you have mixed packages from your distro and from packages.microsoft.com. you need to follow the instructions I linked above and ensure that all of the dotnet packages are coming from one source. They are not able to be mixed.

MarekM25 commented 8 months ago

@baronfel I have the same problem as @Anduin2017. How can I check if my packages are mixed? If they are mixed, what should I do to fix it? I followed official instructions from here: https://learn.microsoft.com/en-us/dotnet/core/install/linux-ubuntu?fbclid=IwAR0fOHfXfHRlQclJVyutLcJ9D_9eXwZH8hFYjgDQ5BNU5sb1n_kodq0qXe0#register-the-microsoft-package-repository

First of all, I used those commands:

declare repo_version=$(if command -v lsb_release &> /dev/null; then lsb_release -r -s; else grep -oP '(?<=^VERSION_ID=).+' /etc/os-release | tr -d '"'; fi)
wget https://packages.microsoft.com/config/ubuntu/$repo_version/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb

Next, I installed:

sudo apt install dotnet-sdk-8.0
sudo apt install dotnet-runtime-8.0

My dotnet info:

dotnet --info
.NET SDK:
 Version:           8.0.101
 Commit:            6eceda187b
 Workload version:  8.0.100-manifests.69afb982

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  22.04
 OS Platform: Linux
 RID:         linux-x64
 Base Path:   /usr/share/dotnet/sdk/8.0.101/

.NET workloads installed:
 Workload version: 8.0.100-manifests.69afb982
There are no installed workloads to display.

Host:
  Version:      8.0.1
  Architecture: x64
  Commit:       bf5e279d92

.NET SDKs installed:
  8.0.101 [/usr/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 8.0.1 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 8.0.1 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  Not found

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

Download .NET:
  https://aka.ms/dotnet/download
akrotov commented 8 months ago

Same issue as users reports below:

dotnet --info .NET SDK: Version: 8.0.101 Commit: 6eceda187b Workload version: 8.0.100-manifests.69afb982

Runtime Environment: OS Name: ubuntu OS Version: 22.04 OS Platform: Linux RID: linux-x64 Base Path: /usr/share/dotnet/sdk/8.0.101/

.NET workloads installed: Workload version: 8.0.100-manifests.69afb982 There are no installed workloads to display.

Host: Version: 8.0.1 Architecture: x64 Commit: bf5e279d92

.NET SDKs installed: 8.0.101 [/usr/share/dotnet/sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 8.0.1 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 8.0.1 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found: None

Environment variables: Not set

global.json file: Not found

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

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

But attempt to run any .net 8 app shows: You must install .NET to run this application.

App: /home/akrotov/train-nn/train Architecture: x64 App host version: 8.0.0 .NET location: Not found

Learn more: https://aka.ms/dotnet/app-launch-failed

Download the .NET runtime: https://aka.ms/dotnet-core-applaunch?missing_runtime=true&arch=x64&rid=linux-x64&os=ubuntu.22.04&apphost_version=8.0.0

Spent half of the night trying all the fixes. The only what worked was setting: export DOTNET_ROOT=/usr/share/dotnet

Seems that with in version 8 dotnet lost ability to write installation path during installation)

P.S it was last time when I've upgraded project to latest released .net version without very serious reasons for this. No updates - no problems :)

MarekM25 commented 7 months ago

export DOTNET_ROOT="/usr/share/dotnet" wasn't enough for me, however changing /etc/environment by adding DOTNET_ROOT="/usr/share/dotnet there worked for me

WeihanLi commented 7 months ago

The same problem met when trying to use a dotnet tool with dotnet-8 SDK installed on Ubuntu from the Microsoft package repository by following the guide on the docs

The environment variable DOTNET_ROOT=/usr/share/dotnet setting works for me

Anduin2017 commented 7 months ago

I finally mitigated via installing from Ubuntu official source:

sudo apt install dotnet8

And everything works fine.