Search code examples
.netvisual-studio-2012nuget

Is there any way to recreate packages.config file?


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

Is there any way to recreate it?


Solution

  • 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>