Skip to content

Instantly share code, notes, and snippets.

@musukvl
Created April 22, 2020 06:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save musukvl/5be7d02bbe83d00aa70a286a18b967a1 to your computer and use it in GitHub Desktop.
Save musukvl/5be7d02bbe83d00aa70a286a18b967a1 to your computer and use it in GitHub Desktop.
Generates nuget install for all references
# place this file to your prepository root, or set the your repository full path to $repositoriesRoot
$repositoriesRoot = Convert-Path .
$files = Get-ChildItem -Path $repositoriesRoot -Filter *.csproj -Recurse -File -Name
$commands = @()
foreach ($fileName in $files) {
$xml = [Xml](Get-Content "$repositoriesRoot\$fileName")
foreach ($item in $xml.SelectNodes("//PackageReference")) {
$attr = $item.Attributes["Include"]
$name = $attr.Value;
$versionAttr = $item.Attributes["Version"]
$version = ""
if (!$versionAttr) {
$versionNode = $item.SelectSingleNode("Version");
$version = $versionNode.InnerText;
}
else {
$version = $versionAttr.Value
}
$commands += "nuget install $name -Version $version"
}
}
$commands = $commands | Sort-Object | Get-Unique
Write-Output $commands
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment