linux - dotnet 命令找不到 .NET Core 2.1 的新安装

标签 linux asp.net-core .net-core

我正在尝试在我的 Debian 9 服务器上托管 ASP.NET Core 应用程序。我之前安装了 .NET Core 1,并且一直在尝试安装 .NET 2.1 的运行时/托管。

我关注了 official installation instructions对于我的发行版,dotnet --version 命令输出 1.0.1,而 dotnet --info 输出

.NET Command Line Tools (1.0.1)

Product Information:
 Version:            1.0.1
 Commit SHA-1 hash:  005db40cd1

Runtime Environment:
 OS Name:     debian
 OS Version:  9
 OS Platform: Linux
 RID:         debian.8-x64
 Base Path:   /opt/dotnet/sdk/1.0.1

当我尝试只运行已复制到服务器的基本模板应用程序时,它会输出

The specified framework 'Microsoft.NETCore.App', version '2.1.0' was not found.
  - Check application dependencies and target a framework version installed at:
      /opt/dotnet/shared/Microsoft.NETCore.App
  - The following versions are installed:
      1.1.1
      1.0.4
  - Alternatively, install the framework version '2.1.0'.

果然,/opt/dotnet/shared/Microsoft.NETCore.App 只包含 1.1.1 和 1.0.4 的子目录,然而...

$ sudo apt install aspnetcore-runtime-2.1
   [sudo] password for root:
   Reading package lists... Done
   Building dependency tree
   Reading state information... Done
   aspnetcore-runtime-2.1 is already the newest version (2.1.2-1).

我必须做什么才能找到运行时?

评论中问题的回答:


$ which dotnet
/usr/local/bin/dotnet

dpkg -L 的输出很长,但我认为给出了问题的原因。 2.1 运行时的文件都在 /usr/share/dotnet 而不是 /opt/dotnet 下。运行 dotnet 使用 /usr/local/bin 中的那个看到旧的运行时,但它看起来像有一个 /usr/bin/dotnet 看看新版本...我按照 Microsoft 的说明进行了两次安装,所以我不确定为什么会如此不同。

最佳答案

当您在命令行中输入 dotnet 时,您的 shell 会在您的 $PATH 中查找它。您似乎安装了两个 dotnet 命令,一个在 /usr/local/bin/dotnet,另一个在 /usr/bin/dotnet/usr/local/bin/ 首先出现在您的 $PATH 中,因此当您键入 dotnet

/usr/local/bin/dotnet 我怀疑是 /opt/dotnet/dotnet 的符号链接(symbolic link)。其中包含 2 个 .NET Core 运行时版本(如 dotnet --info 所示):1.0.4 和 1.1.1。听起来这是由用户手动安装的,可能是通过从发布 tarball 中提取到 /opt/dotnet

(这些版本非常过时。它们还包含已知的安全漏洞)

/usr/share/dotnet/dotnet-*aspnetcore* 包通过 apt 安装>。并且包含版本 2.1 包。

您有几个选项可以解决此问题:

  1. 如果 /usr/local/bin/dotnet 不属于包管理器(dpkg --search/usr/local/bin/dotnet 不属于't list a package), 然后你可以简单地 rm 它。然后 dotnet 将表示 /usr/share/dotnet/dotnet。您还可以删除 /opt/dotnet

  2. 如果 /usr/local/bin/dotnet 由包管理器所有,请在 dpkg --search 输出中找到包的名称,然后删除那个包。

  3. 您可以覆盖 .bashrc(或等效的 shell 配置文件)中的 $PATH。添加一行 export PATH=/usr/bin:/usr/local/bin:/bin:/usr/game

我强烈推荐选项 1。

我不确定为什么这两个安装在不同的位置并使用不同的可执行文件。也许在您安装的版本发布后安装说明已更改并且软件包可用?

关于linux - dotnet 命令找不到 .NET Core 2.1 的新安装,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51642690/

相关文章:

linux - 在 Unix/Linux 中将特定文件从一个文件夹复制到另一个文件夹

linux - 过滤 Linux 命令输出

linux - 如何在 linux 中重定向 ps 命令以查看除/proc 之外的其他文件夹

c# - EFCore 2.0 默认所有日期字段使用 datetime2

asp.net-core - DotNet Core Identity - 用户表与自定义表的关系

c# - "The type mapping for ' Instant ' has not implemented code literal generation"分割实体时

java - 以可移植的方式以编程方式打开文档

c# - ASP.Net Core异常处理中间件

c# - .NET Core 2.2 Azure Function v2 依赖注入(inject)

c# - 从 Visual Studio 2017 RC 降级到 Visual Studio 2015 的解决方案