据我所知,NuGet 旨在作为 Visual Studio 扩展安装:
http://docs.nuget.org/docs/start-here/installing-nuget
如果我需要在一台没有安装VS的机器上使用 NuGet 呢?
具体来说,我想通过 PowerShell 脚本安装 NuGet。
http://docs.nuget.org/docs/start-here/installing-nuget
如果我需要在一台没有安装VS的机器上使用 NuGet 呢?
具体来说,我想通过 PowerShell 脚本安装 NuGet。
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
无法设置属性。此语言模式仅支持核心类型的属性设置。
- HackSlash这里有一段简短的 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中引入的。 这篇文章提供了相关概念。
这似乎也可以做到。 PS 示例:
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Install-PackageProvider -Name NuGet -Scope CurrentUser
以无管理员权限使用NuGet。该命令不适用于Powershell Core。 - KargWare如果没有安装Visual Studio,您可以从以下网址下载Nuget:http://nuget.org/nuget.exe
要使用命令行执行,请查看:http://docs.nuget.org/docs/reference/command-line-reference
对于Powershell,只需将nuget.exe复制到机器上即可。无需安装,只需按照上述文档中的命令执行即可。
http://nuget.org/nuget.exe
上的版本与 https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
上的版本相比较老。 - Alex Angas使用PowerShell,但不需要创建脚本:
Invoke-WebRequest https://dist.nuget.org/win-x86-commandline/latest/nuget.exe -OutFile Nuget.exe
[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