dotnet error : Unable to obtain lock file access on '/tmp/NuGetScratch/lock/

dotnet error : Unable to obtain lock file access on '/tmp/NuGetScratch/lock/

重现步骤

dotnet 构建或 dotnet 运行

预期行为

运行 或构建应用程序

实际行为

Getting ready...
The template "ASP.NET Core with Angular" was created successfully.

Processing post-creation actions...
Running 'dotnet restore' on /home/limup/Documents/Projetos/Limup/salao/salao.csproj...
/usr/share/dotnet/sdk/3.1.101/NuGet.targets(123,5): error : Unable to obtain lock file access on '/tmp/NuGetScratch/lock/b19d3901039706ea82571abad7c98ec690508d4b' for operations on '/home/limup/Documents/Projetos/Limup/salao/obj/salao.csproj.nuget.cache'. This may mean that a different user or administator is holding this lock and that this process does not have permission to access it. If no other process is currently performing an operation on this file it may mean that an earlier NuGet process crashed and left an inaccessible lock file, in this case removing the file '/tmp/NuGetScratch/lock/b19d3901039706ea82571abad7c98ec690508d4b' will allow NuGet to continue. [/home/limup/Documents/Projetos/Limup/salao/salao.csproj]

Restore failed.
Post action failed.
Description: Restore NuGet packages required by this project.
Manual instructions: Run 'dotnet restore'

环境数据

dotnet --info

.NET Core SDK (reflecting any global.json):
Version: 3.1.101
Commit: b377529961

Runtime Environment:
OS Name: fedora
OS Version: 31
OS Platform: Linux
RID: fedora.31-x64
Base Path: /usr/share/dotnet/sdk/3.1.101/

Host (useful for support):
Version: 3.1.1
Commit: a1388f194c

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

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

To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download

观察

尝试了 dotnet restore 中的修复,但我收到了同样的错误。

dotnet sdk 2.0 没有这个问题。

@Omair Majid,见:

[limup@localhost tmp]$ ll -a
total 12
drwxrwxrwt. 22 root  root   480 Jan 15 16:59 .
dr-xr-xr-x. 18 root  root  4096 Jan 10 18:51 ..
drwx------.  2 limup limup   60 Jan 15 16:54 .esd-1000
drwxrwxrwt.  2 root  root    40 Jan 15 16:49 .font-unix
drwxrwxrwt.  2 root  root    60 Jan 15 16:54 .ICE-unix
drwx------.  3 root  root    60 Jan 15 16:49 systemd-private-5f8b1b99edb949b1864fa2e580380675-adb.service-WzMSag
drwx------.  3 root  root    60 Jan 15 16:49 systemd-private-5f8b1b99edb949b1864fa2e580380675-chronyd.service-Rw6V8i
drwx------.  3 root  root    60 Jan 15 16:50 systemd-private-5f8b1b99edb949b1864fa2e580380675-colord.service-9QFuBh
drwx------.  3 root  root    60 Jan 15 16:49 systemd-private-5f8b1b99edb949b1864fa2e580380675-dbus-broker.service-DqpFAf
drwx------.  3 root  root    60 Jan 15 16:54 systemd-private-5f8b1b99edb949b1864fa2e580380675-fwupd.service-eBNBLh
drwx------.  3 root  root    60 Jan 15 16:54 systemd-private-5f8b1b99edb949b1864fa2e580380675-geoclue.service-O6YLYg
drwx------.  3 root  root    60 Jan 15 16:49 systemd-private-5f8b1b99edb949b1864fa2e580380675-ModemManager.service-hHCfHf
drwx------.  3 root  root    60 Jan 15 16:49 systemd-private-5f8b1b99edb949b1864fa2e580380675-rtkit-daemon.service-3A8e9f
drwx------.  3 root  root    60 Jan 15 16:49 systemd-private-5f8b1b99edb949b1864fa2e580380675-switcheroo-control.service-zSjrXg
drwx------.  3 root  root    60 Jan 15 16:49 systemd-private-5f8b1b99edb949b1864fa2e580380675-systemd-logind.service-ohP23f
drwx------.  3 root  root    60 Jan 15 16:50 systemd-private-5f8b1b99edb949b1864fa2e580380675-upower.service-kMAiIg
drwx------.  2 limup limup   40 Jan 15 16:58 Temp-31248c7a-04ad-429c-ab49-4c2ed74a1986
drwx------.  2 limup limup   40 Jan 15 16:58 Temp-8fa994cb-0334-4cf9-886d-103347596108
drwxrwxrwt.  2 root  root    40 Jan 15 16:49 .Test-unix
drwx------.  2 limup limup   40 Jan 15 17:00 tracker-extract-files.1000
-r--r--r--.  1 limup limup   11 Jan 15 16:54 .X0-lock
-r--------.  1 gdm   gdm     11 Jan 15 16:50 .X1024-lock
drwxrwxrwt.  2 root  root    80 Jan 15 16:54 .X11-unix
drwxrwxrwt.  2 root  root    40 Jan 15 16:49 .XIM-unix

我使用以下命令修复了该错误:

export TMPDIR=/tmp/NuGetScratch/
mkdir -p ${TMPDIR}

但是,我收到了另一个错误,我打开了另一个问题 post:Post

在我的例子中,问题是由“锁定文件”(在 Linux 中)的所有权引起的。 我在我的用户下 运行ning dotnet build(没有 sudo),但我的项目是使用 sudo.

创建的

选项 A) 再次使用 sudo

sudo dotnet build

选项 B) 更改 /tmp/NuGetScratch/lock/ 所有权:

sudo chown -R <user>:<user> /tmp/NuGetScratch/

然后,用户可以 运行 dotnet build 无需 sudo。