如何使用dotnet CLI一次更新所有NuGet软件包? [英] How do I update all NuGet packages at once with the dotnet CLI?

查看:175
本文介绍了如何使用dotnet CLI一次更新所有NuGet软件包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为VS Code中的解决方案更新所有NuGet软件包(使用Mac)。有没有一种方法可以通过VS代码或特定的project.json文件来实现?目前,我要一步一步地工作,但我会以为有扩展程序或功能可以帮您吗?

I'm trying to update all NuGet packages for a solution in VS Code (using Mac). Is there a way to achieve that in VS code or for a specific project.json file? At the moment I'm going one by one but I would have thought there is either an extension or a feature that does that for you?

推荐答案

这是将执行此操作的shell脚本和powershell脚本

Here's a shell script and a powershell script that will do this

#!/bin/bash
regex='PackageReference Include="([^"]*)" Version="([^"]*)"'
find . -name "*.*proj" | while read proj
do
  while read line
  do
    if [[ $line =~ $regex ]]
    then
      name="${BASH_REMATCH[1]}"
      version="${BASH_REMATCH[2]}"
      if [[ $version != *-* ]]
      then
        dotnet add $proj package $name
      fi
    fi
  done < $proj
done







$regex = [regex] 'PackageReference Include="([^"]*)" Version="([^"]*)"'
ForEach ($file in get-childitem . -recurse | where {$_.extension -like "*proj"})
{
  $proj = $file.fullname
  $content = Get-Content $proj
  $match = $regex.Match($content)
  if ($match.Success) {
    $name = $match.Groups[1].Value
    $version = $match.Groups[2].Value
    if ($version -notin "-") {
      iex "dotnet add $proj package $name"
    }
  }
}

还应该提到Paket是支持更新的出色替代软件包管理器:

Should also mention Paket as a fantastic alternative package manager that supports update:

https://fsprojects.github.io/Paket/index.html

dotnet工具安装程序包--tool-path .paket

这篇关于如何使用dotnet CLI一次更新所有NuGet软件包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆