Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for bulk-updating references into csproj from commandline(s) #4103

Open
rrelyea opened this issue Dec 13, 2016 · 73 comments
Open

support for bulk-updating references into csproj from commandline(s) #4103

rrelyea opened this issue Dec 13, 2016 · 73 comments
Assignees
Labels
Category:SeasonOfGiving https://devblogs.microsoft.com/nuget/nuget-season-of-giving/#season-of-giving Platform:Xplat Priority:2 Issues for the current backlog. Product:NuGet.exe NuGet.exe Style:PackageReference Triage:NeedsDesignSpec Type:Feature

Comments

@rrelyea
Copy link
Contributor

rrelyea commented Dec 13, 2016

splitting off from #3751 - which now just covers the add side of this work

Spec draft: https://github.com/NuGet/Home/wiki/Support-dotnet-ref-add%7Cupdate%7Cdelete-packageref

nuget.exe update for package reference

@rrelyea
Copy link
Contributor Author

rrelyea commented Dec 13, 2016

since add will support "update", we'll prioritize this task as the lowest of the 4:

  1. add 2) remove 3) list 4) update

@dasMulli
Copy link

dasMulli commented Dec 19, 2016

Would it make sense to allow updating all package references? For a lot of dependencies, it is very quick to do sth like dotnet update pkg --all to begin with when updating a project.

@kjbetz
Copy link

kjbetz commented Nov 14, 2017

I would highly suggest checking out how yarn has taken care of this with yarn upgrade and yarn upgrade-interactive

https://yarnpkg.com/lang/en/docs/cli/upgrade/

https://yarnpkg.com/lang/en/docs/cli/upgrade-interactive/

I would just use the same names as well... dotnet upgrade dotnet upgrade-interactive or possibly dotnet package upgrade dotnet package upgrade-interactive

@rrelyea
Copy link
Contributor Author

rrelyea commented Nov 21, 2017

Notice that #6193 added the additional requests to support cross-project updates, etc...

@mudrz
Copy link

mudrz commented Apr 10, 2018

Since this issue is 2 years old - are there any plans to create any basic cli commands for managing package versions?
Currently it is very inconvenient to manage packages outside of Visual Studio on Windows.

@letmaik
Copy link

letmaik commented Jun 1, 2018

As part of continuous integration I'd like to auto-update dependencies to check that nothing breaks with newer versions. However, this seems impossible without this feature if you manage your dependencies in .csproj files. Any ETA for this? It seems like a basic feature to have.

@mishra14
Copy link
Contributor

mishra14 commented Jun 1, 2018

@letmaik you can always run dotnet add package <package_name>. This command will find the latest version of the package and update it in your csproj.

@dasMulli
Copy link

dasMulli commented Mar 22, 2021

The dotnet commands are non interactive by default

Plus a large set of projects will be in source control (I'd wish for dotnet new templates to initialize a git repo as well just like ng new does for angular if the target dir is not already in VCS), whereas you usually can't git reset --hard your whole linux system (not that I wouldn't have needed it in the past 🤣).

@BlackGad
Copy link
Contributor

@JonDouglas any progress? Seems #5208 this issue also related to this.

  1. Why do you use single source but not the nuget.config?
  2. What about solution level update?
  3. Will there be wildcards?

@Craige
Copy link

Craige commented Sep 28, 2021

What is going on with this?

@nnamdiogbu
Copy link

Hi @JonDouglas, Any updates on this topic?

@JonDouglas
Copy link
Contributor

Sorry, this has not been on my near-term list. I am hopeful to return to this next year. I apologize for not providing an update sooner as I was off on paternity leave and now focusing on some other large features. When this has our attention again, I will post a full spec on https://github.com/NuGet/Home/pulls & ask for everyone here to provide feedback.

I will also incorporate the various comments since my last post when working on that artifact. Thanks all!

@eddex
Copy link

eddex commented Nov 22, 2021

@SimonCropp
Copy link

here is my hacked approach https://github.com/SimonCropp/PackageUpdate

@OskarKlintrot
Copy link

And here's my approach: https://github.com/OskarKlintrot/UpdatR. I tried to make it's output pr- and ci/cd-friendly, similar to nukeeper.

@Balkoth
Copy link

Balkoth commented Apr 21, 2022

I would love to see this feature finally making into dotnet.

@OskarKlintrot
Copy link

Me too, I really hope they also make it stick to supported versions only! That is very useful to have!

@divinebovine
Copy link

If it helps anyone, I just wrote a bash script to update everything to the latest stable. It searches the current directory for all C# projects and updates all outdated packages. I'm sure it could be improved but it works.

for PROJECT in $(find . -iname '*.csproj')
do
  for PACKAGE in $(dotnet list $PROJECT package --outdated | grep '>' | sed -r 's/^ *> ([a-zA-Z0-9\.]*) .*$/\1/gm')
  do
    dotnet add $PROJECT package $PACKAGE
  done
done
echo Update Complete

Here is a vscode task that can be added as a user level task.

{
    "label": "Update Nuget Dependencies",
    "type": "shell",
    "command": "for PROJECT in $(find . -iname '*.csproj'); do for PACKAGE in $(dotnet list $PROJECT package --outdated | grep '>' | sed -r 's/^ *> ([a-zA-Z0-9\\.]*) .*$/\\1/gm'); do dotnet add $PROJECT package $PACKAGE; done; done; echo Update Complete",
    "presentation": {
        "echo": true,
        "reveal": "always",
        "focus": false,
        "panel": "shared",
        "showReuseMessage": true,
        "clear": false
    },
    "problemMatcher": []
}

@JonDouglas
Copy link
Contributor

Hi friends,

I have published a draft proposal for this feature. Please feel free to comment and provide your feedback on it.

#11812

I tried my best to incorporate all the feedback here while also comparing to other ecosystems and existing feedback we've heard over the last year or so.

@RivenSkaye
Copy link

RivenSkaye commented Jul 26, 2023

I'm not sure if this is the right place for this, but on a system with grep, you can implement this with:

dotnet list package --outdated | grep -o '> \S*' | grep '[^> ]*' -o | xargs -L 1 dotnet add package

This uses dotnet list package --outdated to get a list of packages to update, some grep commands that I should be embarassed about writing to extract the package names, and then dotnet add package to do the actual update.

@brendanlong @AlirezaHaghshenas you can even chop out a grep call if you have GNU Grep (or another grep that provides PCRE expressions) using dotnet list packages --outdated | grep -oP "\>\s+\K\S+" | xargs -L 1 dotnet add package
grep -o: only keep matching components
grep -P: PCRE to allow for special options
\>\s+: match the starting segment
\K: keep matches after this point, which prevents the second grep from being required to chop off the > prefix
\S+: all uninterrupted non-whitespace characters, prevents empty lines and should be a tad more robust against formatting differences

Might just toss a utility script somewhere on my path to combine this with @divinebovine's outer loop logic

@MMeshkiny
Copy link

dotnet list package --outdated | grep -o '> \S.' | grep '[^> ].' -o | awk '{system("dotnet add package "$1 " -v " $4)}'

@marshallr12
Copy link

So about 8 years later, there's still no dotnet update command?

@NCLnclNCL
Copy link

hahâ

@reinux
Copy link

reinux commented Jan 9, 2024

dotnet list package --outdated | grep -o '> \S.' | grep '[^> ].' -o | awk '{system("dotnet add package "$1 " -v " $4)}'

@MMeshkiny Just for the benefit of anyone else looking for solutions, could you specify which environment/shell this is for? @RivenSkaye 's command worked in fish shell, but this one didn't.

@RivenSkaye
Copy link

Both should work in any env providing the GNU utilities (there is also a GNU awk), though both just use pretty standard POSIX-y tooling. Try and see if your package manager provides an awk package

@spaasis
Copy link

spaasis commented Feb 21, 2024

While we wait for official support there's a pretty functional dotnet tool https://github.com/dotnet-outdated/dotnet-outdated

@smoothdeveloper
Copy link

smoothdeveloper commented Apr 3, 2024

I'm a bit partial to the famed dotnet paket install, but I would really do with a bulk update of packages that works on a .sln in projects that haven't adopted paket.

Edit: it should work on all *proj files, not only .csproj, unless https://twitter.com/DotNetIsCSharp has taken over.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category:SeasonOfGiving https://devblogs.microsoft.com/nuget/nuget-season-of-giving/#season-of-giving Platform:Xplat Priority:2 Issues for the current backlog. Product:NuGet.exe NuGet.exe Style:PackageReference Triage:NeedsDesignSpec Type:Feature
Projects
None yet
Development

No branches or pull requests