![](/img/trans.png)
[英]Powershell: How do I install the Nuget provider for PowerShell on a unconnected machine so I can install a nuget package from the PS command line?
[英]How can I reference NuGet package files from a PowerShell script?
我正在使用NuGet在Visual Studio上下文之外進行程序包管理。 我有一個packages.config文件,可以通過nuget restore
其nuget restore
到我項目中的packages目錄中。
NuGet將每個軟件包下載到該軟件包的名稱加上其版本號的目錄中。 我需要從PowerShell中的這些程序包訪問文件,但我想避免在文件路徑中包含版本號,因為如果要在packages.config中推進版本,則需要手動更改。
我會使用包配置文件自己構建路徑
# Get solution folder
$PathToSolution = "C:\Some\Path\SolutionFolder"
# find all packages under the solution folder
$configs = gci $PathToSolution -Filter packages.config -recurse
# get content of every package config file
$configs.fullname | %{[xml]$packages = Get-Content $_;
$packages.packages.package | foreach{
# Get pacakge attributes
$packageId=$_.id;
$packageVersion=$_.version;
# Build the path from the build attributes
$Path="$PathToSolution\packages\$packageId.$PackageVersion";
Write-output $Path}}
我唯一要添加的是檢查包路徑的唯一性,因為很可能是在多個項目中使用了某些包
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.