Installing dotnet-sdk-7.0 on Ubuntu 20.04 (and 22.04) breaks net6.0 projects (and net7.0 doesn't work either). Sudo needed to build after this
Asked Answered
A

2

8

I follow these instructions to install dotnet on Ubuntu 20.04. Install the sdk Ubuntu 20.04
These instruction is at this time: wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb sudo dpkg -i packages-microsoft-prod.deb rm packages-microsoft-prod.deb

sudo apt-get update && \ sudo apt-get install -y dotnet-sdk-6.0
Now I can build net6.0 projects.

I then install 7
sudo apt install dotnet-sdk-7.0

Then when I try to build my net6.0 project I get:

CSC : warning CS8034: Unable to load Analyzer assembly /usr/share/dotnet/sdk/7.0.200/Sdks/Microsoft.NET.Sdk.Web/analyzers/cs/Microsoft.AspNetCore.Analyzers.dll : Could not load file or assembly 'Microsoft.AspNetCore.Analyzers, Version=7.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. Access is denied.

And the same error on a bunch of other assemblies. I should not get an error about a net7.0 assembly when I try to build my net6.0 project. If I change the target framework in csproj to net7.0, I get the same error.

I can however still build my project both as net6.0 and as net7.0 if I add sudo. The permissions are what you would expect:

ls -l /usr/share/dotnet/sdk/7.0.200/Sdks/Microsoft.NET.Sdk.Web/analyzers/cs/Microsoft.AspNetCore.Analyzers.dll
-rw-r--r-- 1 root root 42664 jan 30 23:01 /usr/share/dotnet/sdk/7.0.200/Sdks/Microsoft.NET.Sdk.Web/analyzers/cs/Microsoft.AspNetCore.Analyzers.dll

It is the same permissions as the corresponding net6.0 file.

I tried this:

  • I uninstalled everything dotnet.
    sudo apt remove dotnet-sdk-6.0 dotnet-sdk-7.0 dotnet sudo apt clean autoclean autoremove
  • And there was nothing left under /usr/shar/dotnet
  • Reinstalled
  • Tried adding:
export DOTNET_ROOT=/usr/share/dotnet
export PATH=$PATH:$DOTNET_ROOT

This made no difference.
My colleague found that the installation of dotnet-sdk-7.0 on Ubuntu 22.04 also destroyed the possibility to build net6.0 projects. However I don't have all the details on that.

Some of the output from dotnet --info

.NET SDK:
 Version:   7.0.200

.NET SDKs installed:
  6.0.406 
  7.0.200 

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.14
  Microsoft.AspNetCore.App 7.0.3 
  Microsoft.NETCore.App 6.0.14 
  Microsoft.NETCore.App 7.0.3 

Environment variables:
  Not set
global.json file:
  Not found
Autobiographical answered 24/2, 2023 at 13:56 Comment(1)
Unintalling dotnet-sdk-7.0 restores the ability to build net6.0 projectsAutobiographical
A
9

I took a new stab at this problem. I followed the instructions here: https://learn.microsoft.com/en-us/dotnet/core/install/linux-ubuntu#troubleshooting

The two bash instructions, first this:

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

and then this:

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/20.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-7.0

Then it suddenly worked

Autobiographical answered 21/3, 2023 at 9:35 Comment(2)
Thanks for sharing. Sometimes MS adds a lot of verbose in their instructions... I can confirm this solution also works for Debian 12.Handmaiden
I get error accessing archive: packages-microsoft-prod.debUrea
E
0

It's a horrible workaround but I've been having the same issue and I found that running dotnet build as root (i.e. sudo dotnet build) allowed the build to succeed.

Like yours, my permissions on the reference files look fine. I suspect there is some internal tooling in the 7.0 SDK that is being installed with incorrect permissions.

My dotnet --info, for reference:

.NET SDK:
 Version:   7.0.201
 Commit:    68f2d7e7a3

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

Host:
  Version:      7.0.3
  Architecture: x64
  Commit:       0a2bda10e8

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

.NET runtimes installed:
  Microsoft.AspNetCore.App 7.0.3 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 7.0.3 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Elatia answered 2/3, 2023 at 0:33 Comment(1)
Yes, that workaround is actually in my question if you read carefullyAutobiographical

© 2022 - 2024 — McMap. All rights reserved.