簡體   English   中英

如何從PowerShell腳本引用NuGet軟件包文件?

[英]How can I reference NuGet package files from a PowerShell script?

我正在使用NuGet在Visual Studio上下文之外進行程序包管理。 我有一個packages.config文件,可以通過nuget restorenuget 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM