Error: [/usr/share/dotnet/host/fxr] does not exist

When

Occurs when running dotnet publish --configuration Release or dotnet run

Cause

conflict between the microsoft and ubuntu package repository when dotnet was installed

Solution

Remove all installed dotnet packages

sudo apt remove dotnet* aspnetcore* netstandard*

create a dotnet preference file in /etc/apt/preferences.d with a name like dotnet.pref

Package: *
Pin: origin "packages.microsoft.com"
Pin-Priority: 1001

reinstall dotnet

sudo apt update
sudo apt install -y dotnet-sdk-6.0