1

We have a few hundred Visual Studio solutions of varying ages and we have an internally written NuGet package that many of them consume. We want to eliminate this NuGet package and remove it from these solutions and their projects (no more reference in csproj or packages.config).

Through a script, I can create a branch for each and do a pull request when the package removal is done. As those PRs are approved, the builds/deploy will happen in an automated fashion. So, the only manual part seems to be this package uninstall.

These are framework apps and the dotnet remove command won't work on these. The nuget.exe only seems to allow delete from feeds, not solutions/projects. I'm still looking, but haven't found other options.

I'd rather not have to open every one of these solutions in VS to remove this package. Can this be scripted in powershell or c# easily?

Paul G
  • 2,722
  • 4
  • 37
  • 54
  • 1
    Use a replace all for the csproj files? (assuming you're using Csproj SDK style) – Julian Mar 27 '20 at 20:28
  • May be an option. Thanks. We probably have a half dozen varations of strings that might be in there due to version number diffs, but still doable. I was hoping there would be some legit tool that I'm missing. It seems like something they should have made possible. Mass package management appears to be a big gap in the nuget tool belt. – Paul G Mar 27 '20 at 20:32
  • Have you tried to follow [Manage packages for the solution](https://learn.microsoft.com/en-us/nuget/consume-packages/install-use-packages-visual-studio#manage-packages-for-the-solution)? – Pavel Anikhouski Mar 27 '20 at 20:39
  • You can also try this approach [How do I uninstall \*all\* nuget packages from a solution in Visual Studio](https://stackoverflow.com/questions/28596666/how-do-i-uninstall-all-nuget-packages-from-a-solution-in-visual-studio) – Pavel Anikhouski Mar 27 '20 at 20:41
  • I can do that for each solution, but that is exactly what I'm trying to avoid. Are you suggesting that there is a way to use that to touch multiple solutions in mass @PavelAnikhouski? – Paul G Mar 27 '20 at 20:42
  • 1
    @PaulG At the beginning of the question you are stating _We have a few hundred Visual Studio projects_ I don't think that nuget cli or VS will work across multiple solutions. It can operate only across all projects inside one solution – Pavel Anikhouski Mar 27 '20 at 20:44
  • 1
    @PavelAnikhouski Good point, I'll edit that to make it clearer. – Paul G Mar 27 '20 at 20:48
  • 1
    for projects using PackageReference, it's safe to just modify the project file and remove the single line. For projects that use packages.config (PC), uninstalling though Visual Studio is the only supported method. With PC projects, NuGet modifies the project file to consume each asset from the package, and only by loading the project in VS can NuGet figure out which lines in the project probably came from the packaage and can be deleted on uninstall. – zivkan Mar 28 '20 at 11:55

1 Answers1

1

It looks like one possible solution may be to use PowerShell, but from within the Package Manager Console inside Visual Studio.

I'm experimenting with something like this:

$projects = Get-ChildItem 'C:\Repos\' -File -Include *.csproj -Recurse; foreach($project in $projects) {Uninstall-Package -Id PackageThatMustDie -project $project.FullName}
Paul G
  • 2,722
  • 4
  • 37
  • 54
  • the answer is essentially.. it will need to be automated, and 'yes' - it can be done fairly easily using any system language. For your example using powershell, I would recommend you use powershell workflow with foreach parallel, and I suggest you not put all of your code on one line. – Brett Caswell Mar 27 '20 at 22:28
  • I'd be surprised if that works, but if it does, that's great. I'd expect the project needs to be loaded in the current solution for this to work, as the csproj gets modified by the project system APIs, NuGet doesn't edit the projcet file directly. Well, under normal circumstances anyway. – zivkan Mar 28 '20 at 11:51
  • Since your issue solved by yourself, I suggest you could mark your answer so that it will help other community members search and handle similar issues. Thanks:) – LoLance Mar 31 '20 at 09:12