据我所知,NuGet应该作为Visual Studio扩展安装:
http://docs.nuget.org/docs/start-here/installing-nuget
但是如果我在没有安装VS的机器上需要NuGet呢?
具体来说,我想通过PowerShell脚本安装NuGet。
答案 0 :(得分:85)
free(arr);
答案 1 :(得分:35)
这是一个简短的PowerShell脚本,可以执行您可能期望的操作:
$sourceNugetExe = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
$targetNugetExe = "$rootPath\nuget.exe"
Invoke-WebRequest $sourceNugetExe -OutFile $targetNugetExe
Set-Alias nuget $targetNugetExe -Scope Global -Verbose
请注意Invoke-WebRequest
cmdlet随PowerShell v3.0到达。 This article提出了这个想法。
答案 2 :(得分:9)
这似乎也是这样做的。 PS示例:
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
答案 3 :(得分:8)
如果没有Visual Studio,您可以从http://nuget.org/nuget.exe
中获取Nuget对于使用此命令行执行,请查看:http://docs.nuget.org/docs/reference/command-line-reference
关于Powershell,只需将nuget.exe复制到计算机即可。无需安装,只需使用上述文档中的命令执行即可。
答案 4 :(得分:3)
使用PowerShell但无需创建脚本:
Invoke-WebRequest https://dist.nuget.org/win-x86-commandline/latest/nuget.exe -OutFile Nuget.exe
答案 5 :(得分:1)
以上解决方案均不适用于我,我发现article解释了该问题。系统上的安全协议已被弃用,因此显示一条错误消息,指出ProviderPackage没有找到匹配项。
这是升级安全协议的基本步骤:
运行两个cmdlet来设置.NET Framework强密码加密注册表项。之后,重新启动PowerShell,并检查是否添加了安全协议TLS 1.2。最后,安装PowerShellGet模块。
第一个cmdlet是在64位.Net Framework(版本4及更高版本)上设置强大的加密技术。
[PS] C:\>Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
1
[PS] C:\>Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
The second cmdlet is to set strong cryptography on 32 bit .Net Framework (version 4 and above).
[PS] C:\>Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
1
[PS] C:\>Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
Restart Powershell and check for supported security protocols.
[PS] C:\>[Net.ServicePointManager]::SecurityProtocol
Tls, Tls11, Tls12
1
2
[PS] C:\>[Net.ServicePointManager]::SecurityProtocol
Tls, Tls11, Tls12
Run the command Install-Module PowershellGet -Force and press Y to install NuGet provider, follow with Enter.
[PS] C:\>Install-Module PowershellGet -Force
NuGet provider is required to continue
PowerShellGet requires NuGet provider version '2.8.5.201' or newer to interact with NuGet-based repositories. The NuGet provider must be available in 'C:\Program Files\PackageManagement\ProviderAssemblies' or
'C:\Users\administrator.EXOIP\AppData\Local\PackageManagement\ProviderAssemblies'. You can also install the NuGet provider by running 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShellGet to install
and import the NuGet provider now?
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): Y
[PS] C:\>Install-Module PowershellGet -Force
NuGet provider is required to continue
PowerShellGet requires NuGet provider version '2.8.5.201' or newer to interact with NuGet-based repositories. The NuGet provider must be available in 'C:\Program Files\PackageManagement\ProviderAssemblies' or
'C:\Users\administrator.EXOIP\AppData\Local\PackageManagement\ProviderAssemblies'. You can also install the NuGet provider by running 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShellGet to install
and import the NuGet provider now?
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): Y