我需要在基于Linux的机器上安装NuGet。当我在Windows机器上使用以下命令时,它可以正常工作:
nuget install packages.config
但是我无法在Linux机器上执行此操作,该怎么做呢?
如果你已经按照(有点烦人的)安装步骤安装了 .Net Core 并从 https://www.microsoft.com/net/core 设置好 apt 软件库,那么你只需要执行以下操作:
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
nuget update -self
仍然无法正常工作 :( - kuga安装Mono,然后下载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 "$@"
- Erik A. Brandstadmoennuget apt包在Linux上无法正常工作,而exe文件则是针对Windows的。如果要运行nuget,最简单的方法是使用mono包装器。
sudo apt-get install mono-complete
//download nuget.exe
mono nuget.exe install
Install Mono 4.4.2 or later.
Execute the following command at a shell prompt (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
Create an alias by adding the following script to the appropriate file for your OS (typically ~/.bash_aliases
or ~/.bash_profile
)(Bash):
# Create as alias for nuget
alias nuget="mono /usr/local/bin/nuget.exe"
Reload the shell. Test the installation by entering nuget
with no parameters. NuGet CLI help should display.
nuget
,则需要按照以下步骤操作:
通过wget https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
下载nuget.exe
创建名为nuget
的bash文件:
> nuget
# Or
vi nuget
vim nuget
,然后按下i
):# Edit the file with - make sure to add the correct path to nuget.exe file
'nuget.exe' $@ &
# Make it executable
chmod +x nuget
# Edit .bashrc
vi .bashrc
export PATH=/path/to/nuget-folder:$PATH
。如果你只需要软件包,一个快速而简单的方法可能是使用curl
或wget
和unzip
。脚本可能如下:
curl -L -o package.zip https://www.nuget.org/api/v2/package/<target_package>
unzip package.zip -d <target_folder>
注意 -L
curl 标志,它告诉 curl 跟随任何重定向。通常情况下,nuget 会将您重定向到 CDN。
现在,您已经在所需的文件夹中拥有最新的 nuget 包。如果需要,您可以通过在 URL 后附加 /<version>
来针对特定版本。
示例:
curl -L -o package.zip https://www.nuget.org/api/v2/package/Microsoft.Azure.Kusto.Language
...
unzip package.zip -d test
Archive: package.zip
inflating: test/_rels/.rels
inflating: test/Microsoft.Azure.Kusto.Language.nuspec
inflating: test/lib/net472/Kusto.Language.dll
inflating: test/lib/net472/Kusto.Language.xml
inflating: test/lib/net5.0/Kusto.Language.dll
inflating: test/lib/net5.0/Kusto.Language.xml
inflating: test/lib/netcoreapp2.1/Kusto.Language.dll
inflating: test/lib/netcoreapp2.1/Kusto.Language.xml
inflating: test/lib/netstandard2.0/Kusto.Language.dll
inflating: test/lib/netstandard2.0/Kusto.Language.xml
inflating: test/EULA-agreement.txt
inflating: test/MSFT.png
inflating: test/[Content_Types].xml
inflating: test/package/services/metadata/core-properties/0878db782482414487821399a0d09728.psmdcp
extracting: test/.signature.p7s
cat test/Microsoft.Azure.Kusto.Language.nuspec | grep "<version>"
<version>11.1.0</version>
curl -L -o package.zip https://www.nuget.org/api/v2/package/Newtonsoft.Json/12.0.2
...
unzip package.zip -d test
Archive: package.zip
inflating: test/LICENSE.md
inflating: test/Newtonsoft.Json.nuspec
inflating: test/packageIcon.png
inflating: test/README.md
inflating: test/[Content_Types].xml
inflating: test/_rels/.rels
inflating: test/lib/net20/Newtonsoft.Json.dll
inflating: test/lib/net20/Newtonsoft.Json.xml
inflating: test/lib/net35/Newtonsoft.Json.dll
inflating: test/lib/net35/Newtonsoft.Json.xml
inflating: test/lib/net40/Newtonsoft.Json.dll
inflating: test/lib/net40/Newtonsoft.Json.xml
inflating: test/lib/net45/Newtonsoft.Json.dll
inflating: test/lib/net45/Newtonsoft.Json.xml
inflating: test/lib/net6.0/Newtonsoft.Json.dll
inflating: test/lib/net6.0/Newtonsoft.Json.xml
inflating: test/lib/netstandard1.0/Newtonsoft.Json.dll
inflating: test/lib/netstandard1.0/Newtonsoft.Json.xml
inflating: test/lib/netstandard1.3/Newtonsoft.Json.dll
inflating: test/lib/netstandard1.3/Newtonsoft.Json.xml
inflating: test/lib/netstandard2.0/Newtonsoft.Json.dll
inflating: test/lib/netstandard2.0/Newtonsoft.Json.xml
inflating: test/package/services/metadata/core-properties/66867671be6046c2a70df93bfa9634b8.psmdcp
extracting: test/.signature.p7s
cat test/Newtonsoft.Json.nuspec | grep "<version>"
<version>12.0.2</version>