Jam*_* Ko 13 .net c# powershell nuget nuget-package
我正在编写一个使用Mono.Cecil库的PowerShell脚本.我如何安装软件包,以便在脚本中使用它?谢谢!
(为了记录,我在询问之前尝试了谷歌搜索,但所有出现的结果都是关于PMC和Visual Studio的结果,这与这个问题无关.)
~5.x版本的PowerShell默认包含nuget包源,但它不起作用:
PS > Get-PackageSource
Name ProviderName IsTrusted Location
---- ------------ --------- --------
nuget.org NuGet False https://api.nuget.org/v3/index.json
PSGallery PowerShellGet False https://www.powershellgallery.com/api/v2/
Run Code Online (Sandbox Code Playgroud)
如果你Unregister-PackageSource -Source nuget.org和Register-PackageSource -Location https://www.nuget.org/api/v2 -name nuget.org -Trusted我能够Install-Package从PowerShell 安装nuget papckages ,而不是在visual studio中.从这个SO答案中得到了想法.
我不知道除去nuget.org源码的v3版本还有什么其他可能的负面影响,但我已经用这种方式运行一段时间了,事情看起来还不错,你的里程可能会有所不同.
作为替代方案,这里有一个例子,通过拉下nuget.exe来完成工作,即使它是一个非常糟糕的方式来执行此操作:
function Install-InvokeOracleSQL {
$ModulePath = (Get-Module -ListAvailable InvokeSQL).ModuleBase
Set-Location -Path $ModulePath
if ($PSVersionTable.Platform -ne "Unix") {
$SourceNugetExe = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
$TargetNugetExe = ".\nuget.exe"
Invoke-WebRequest $sourceNugetExe -OutFile $targetNugetExe
.\nuget.exe install Oracle.ManagedDataAccess
Remove-Item -Path $TargetNugetExe
} elseif ($PSVersionTable.Platform -eq "Unix") {
nuget install Oracle.ManagedDataAccess.Core -Version 2.12.0-beta2
}
}
Run Code Online (Sandbox Code Playgroud)
通过指定源,我能够在PowerShell 6(核心)中安装软件包:
PS > install-package gudusoft.gsqlparser -source https://www.nuget.org/api/v2
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5326 次 |
| 最近记录: |