Is there any way to recreate packages.config file?

13,314

Solution 1

It's kind of tricky to do it in an automated way. Easiest is to simply re-create the packages.config manually, added entries for each directory in the packages dir. For example, I have the following dirs in my packages directory:

Microsoft.Bcl.1.1.3
Microsoft.Bcl.Async.1.0.16
Microsoft.Net.Http.2.2.15
Newtonsoft.Json.5.0.8
repositories.config
WindowsAzure.MobileServices.1.0.2
WPtoolkit.4.2013.08.16

If I were to re-create the packages.config, I could simply take the directory name, separate the version number and create a line for each package like:

  <package id="Microsoft.Bcl" version="1.1.3" targetFramework="wp71" />

adding the targetFramework attribute to whatever target that project was using.

Then wrap all of those <package> elements with

<?xml version="1.0" encoding="utf-8"?>
<packages>
 <!--...-->
</packages>

Resulting in something like this:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Microsoft.Bcl" version="1.1.3" targetFramework="wp71" />
  <package id="Microsoft.Bcl.Async" version="1.0.16" targetFramework="wp71" />
  <package id="Microsoft.Net.Http" version="2.2.15" targetFramework="wp71" />
  <package id="Newtonsoft.Json" version="5.0.8" targetFramework="wp71" />
  <package id="WindowsAzure.MobileServices" version="1.0.2" targetFramework="wp71" />
  <package id="WPtoolkit" version="4.2013.08.16" targetFramework="wp71" />
</packages>

Solution 2

An easier way will be just go to Nuget and reinstall the packages. It will create the package.config file

Share:
13,314
StackOverflower
Author by

StackOverflower

Updated on June 09, 2022

Comments

  • StackOverflower
    StackOverflower almost 2 years

    I accidentally missed to upload to source control NuGet packages.config file and it got deleted somehow :(

    Is there any way to recreate it?

  • jpierson
    jpierson almost 9 years
    Doing so will upgrade to the newest version of the packages though which may not be desirable.
  • Atif
    Atif over 7 years
    So new to nuget myself. nuget install packagename doesn't seem to generate a configuration file.. Just seems to download the packages into the local directory. Am I missing something?
  • Atif
    Atif over 7 years
    Looks like they may be moving to a json format: docs.nuget.org/Consume/ProjectJson-Format