skip to Main Content

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

2

Answers


  1. Chosen as BEST ANSWER

    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


  2. 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]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search