![](/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.