Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 221 Vote(s) - 3.66 Average
  • 1
  • 2
  • 3
  • 4
  • 5
NuGet: Update a package to a specific version in all projects via PowerShell or CMD

#1
We have a scenario, where different teams work on different parts of a larger product. From time to time, all Visual Studio Projects of all Solutions there need to get some of their referenced NuGet packages updated. As a result of that update, all projects in the whole source tree should reference the same versions of the packages.

Is there a way to update a specific NuGet package to a specific version **in all projects** using some **automatic approach** like **PowerShell** scripts?

Edit:
Is there a way to somehow load the necessary parts of Visual Studio and NuGet to also **update the assembly references correctly**?

Example:

NuGetScript Update Solution.sln PackageName -version NewVersion
or

NuGetScript Update PathToProjects PackageName -version NewVersion

There are too many components to load all of them in Visual Studio and update them manually via package manager UI.
Reply

#2
Please use following command line in Package Manager Console window to update a specific package in one solution.

> Get-Project -All | Update-Package PackageName -Version newVersion

Reply

#3
You can create a PowerShell script to search all the project files or packages.config files in your solution and then call [nuget update][1] command to update the packages.

However, there is a limitation when update packages outside of Visual Studio, I would recommend you to do this from Visual Studio:

> The update command will download and extract all new packages to the
> packages folders. Assembly references will be updated in the project
> file, however this is limited to only existing references. If a new
> package has an added assembly it will not be added as part of the
> update command. New package dependencies will also not have their
> assembly references added. To perform a complete update use Visual
> Studio.


[1]:

[To see links please register here]

Reply

#4
*The following script was found somewhere else. I have tried it with my projects. I don't have the original link*

The following script does:

1. run `restore` command on any solutions found within a folder
2. Finds all `packages.config` files containing the package id name provided
3. runs `update` command using the `packages.config` file and the package name as parameters

This assumes that nuget.exe is present in the folder where you will be running this from


param(
[Parameter(Mandatory=$true)]
[string]$packageId
)

Get-ChildItem *.sln -recurse | %{.\\nuget.exe restore $_.fullname}

Get-ChildItem packages.config -Recurse `
| Where-Object {$_ | Select-String -Pattern $packageId} `
| %{.\\nuget.exe update -Id $packageId $_.FullName}
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through