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

问题描述

我正在尝试为 VS Code(使用 Mac)中的解决方案更新所有 NuGet 包.有没有办法在 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?

推荐答案

基于 Jon Canning 的 powershell 解决方案.我修复了一个小错误,即只更新了第一个依赖项,而不是项目文件的所有依赖项.

Based on Jon Canning's powershell solution. I fixed a small bug where only the first dependency was being updated and not all the dependencies for the project file.

$regex = 'PackageReference Include="([^"]*)" Version="([^"]*)"'

ForEach ($file in get-childitem . -recurse | where {$_.extension -like "*proj"})
{
    $packages = Get-Content $file.FullName |
        select-string -pattern $regex -AllMatches |
        ForEach-Object {$_.Matches} |
        ForEach-Object {$_.Groups[1].Value.ToString()}|
        sort -Unique

    ForEach ($package in $packages)
    {
        write-host "Update $file package :$package"  -foreground 'magenta'
        $fullName = $file.FullName
        iex "dotnet add $fullName package $package"
    }
}

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

07-24 22:29