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

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.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 7
  • Comments: 16 (9 by maintainers)

Most upvoted comments

@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

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

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 😃

Thanks @baronfel

I removed DOTNET_ROOT, the Linux executable works fine now!

edi@edi-virtual-machine:~/curry/bin/Release/net8.0/publish$ ./curry
Hello

I finally mitigated via:

Clean first:

sudo apt autoremove dotnet* --purge
sudo apt autoremove aspnetcore* --purge
sudo rm ~/.dotnet -rvf
sudo rm /etc/apt/sources.list.d/microsoft-prod.list
sudo rm /etc/apt/trusted.gpg.d/microsoft.asc.gpg

installing from Ubuntu official source:

sudo apt update
sudo apt install dotnet8

And everything works fine.

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

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