【问题标题】:How to install NuGet from command line on linux如何在 Linux 上从命令行安装 NuGet
【发布时间】:2016-06-30 09:07:01
【问题描述】:

我需要在基于 Linux 的机器上安装 NuGet。当我在 Windows 机器上使用以下命令时,它工作正常。

nuget install packages.config

但是我在linux机器上无法做到这一点,如何实现呢?

【问题讨论】:

标签: linux nuget


【解决方案1】:

一旦您按照(有点烦人的)安装步骤安装了 .Net 核心并从 https://www.microsoft.com/net/core 设置了 apt repo,您​​就可以这样做了:

sudo apt install nuget

并且您将在本地机器上拥有一个可以工作的 nuget:

$ cat /etc/issue
Ubuntu 16.04.1 LTS \n \l

$ nuget
NuGet Version: 2.8.7.0
usage: NuGet <command> [args] [options] 
Type 'NuGet help <command>' for help on a specific command.

请注意,在撰写本文时运行nuget update -self,因为虽然它会成功安装更新版本的 nuget,但该版本实际上不会运行。

如果你确实破坏了它,你总是可以把它吹走并重新安装:

sudo apt remove nuget
sudo apt install nuget

【讨论】:

  • 我在 openSuse 15.0 上尝试了这个答案,但没有成功。给我这个输出Retrieving repository 'openSUSE-Leap-15.0-Update' metadata ...............[done] Building repository 'openSUSE-Leap-15.0-Update' cache ....................[done] Loading repository data... Reading installed packages... 'nuget' not found in package names. Trying capabilities. No provider of 'nuget' found. Resolving package dependencies...
  • @mdzeko 在 openSuse 上,您可能需要使用“mono-nuget”而不是 nuget 作为包名;我不知道他们为什么选择在那个下打包,但是你可以在这里看到包 --> software.opensuse.org/ymp/openSUSE:Leap:15.1/standard/…
  • 谢谢,我已经看到并尝试过,但无济于事。我有一个运行 Debian 的容器,所以你的原始答案毕竟是有帮助的。再次感谢。
  • 这不再起作用了。较新的版本需要 dotnet-sdk 或 mono-complete
【解决方案2】:

安装单声道,然后下载 nuget:

sudo apt-get install mono-complete
wget https://dist.nuget.org/win-x86-commandline/latest/nuget.exe

然后使用mono nuget.exe 运行它。

【讨论】:

  • 您可能还想将它复制到/usr/lib/nuget/NuGet.exe,以便nuget 命令可以工作。那个在 Ubuntu 16.4 上看起来像这样:``` #!/bin/sh exec /usr/bin/cli /usr/lib/nuget/NuGet.exe "$@" ```
  • nuget 有一些受单声道版本影响的怪异挑剔的兼容性问题,因此请确保您实际上是在拉取最新版本。我不相信 apt 总是会得到最新的:mono-project.com/download/stable/#download-lin-ubuntu
  • 在 Ubuntu 16.04 上,最新 (dist.nuget.org/win-x86-commandline/latest/nuget.exe) 版本的 nuget 使用比系统 mono 支持的更新的框架。
  • 对于 16.04 4.5.1 是最新的。 dist.nuget.org/win-x86-commandline/v4.5.1/nuget.exe(4.6.2不行)
  • 只要在 linux / wsl 上运行 nuget 时遇到 System.Net.Http 错误的任何人都可以在此处添加此内容,即使似乎安装了 mono,也请尝试安装 mono-complete。
【解决方案3】:

nuget apt 包在 linux 上并不能真正运行,而 exe 则适用于 windows。如果你想运行 nuget,最简单的方法是使用单声道包装器。

sudo apt-get install mono-complete
//download nuget.exe
mono nuget.exe install

【讨论】:

  • 采用了这个解决方案。 .NET for Linux 不支持 32 位。
【解决方案4】:

如果你想在 WSL2 中使用nuget,步骤如下。

  1. 通过wget https://dist.nuget.org/win-x86-commandline/latest/nuget.exe下载nuget.exe

  2. 创建一个名为 nuget 的 bash 文件:

> nuget
# Or
vi nuget
  1. 使用以下内容编辑文件(vim nuget,然后是i):
# Edit the file with - make sure to add the correct path to nuget.exe file
'nuget.exe' $@ &
  1. 使其可执行。
# Make it executable
chmod +x nuget
  1. 添加到 $PATH 环境变量
# Edit .bashrc
vi .bashrc
  1. 在 .bashrc 文件中插入 export PATH=/path/to/nuget-folder:$PATH

【讨论】:

    【解决方案5】:

    关注Microsoft instructions for installing Nuget on Linux

    1. 安装Mono 4.4.2 or later

    2. 在 shell 提示符 (Bash) 处执行以下命令:

      # Download the latest stable `nuget.exe` to `/usr/local/bin` 
      sudo curl -o /usr/local/bin/nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
      
    3. 通过将以下脚本添加到适合您操作系统的文件(通常为 ~/.bash_aliases~/.bash_profile)来创建别名(Bash):

      # Create as alias for nuget
      alias nuget="mono /usr/local/bin/nuget.exe"
      
    4. 重新加载外壳。通过不带参数输入nuget 来测试安装。应显示 NuGet CLI 帮助。

    【讨论】:

      猜你喜欢
      • 2017-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-28
      • 2018-09-12
      • 1970-01-01
      相关资源
      最近更新 更多