SharePoint 2013: How to extract all the WSPs in a farm!

A while ago I talked about how to extract all the WSPs in a SharePoint Farm as you can see in this article. After reviewing again this article, I noted that the way I used there to extract the WSPs didn’t work right for SharePoint 2013. Fortunately, I quickly found another approach to extract all the WSPs and this is what I’m sharing tin this article. AS you can see, using the server side API you can easily access to the collection of farm solutions using a SPSolutionCollection object and simply iterate through it in order to save each .WSP.

   1: static void ExtractAllWSPs_2()

   2: { 

   3:     SPFarm spfFarm=SPWebService.ContentService.Farm;

   4:     int iSolutionsNumber = 0;

   5:     SPSolutionCollection spsFarmSolutions=

   6:         spfFarm.Solutions;

   7:     Console.WriteLine("Starting the extraction process...");

   8:     Console.WriteLine("The number of solutions found is {0}",

   9:     spsFarmSolutions.Count);

  10:         

  11:     foreach (SPSolution spfSolution in spsFarmSolutions)

  12:     {

  13:         Console.WriteLine("Extracting solutiin {0}", spfSolution.DisplayName);

  14:         spfSolution.SolutionFile.SaveAs(spfSolution.DisplayName);

  15:         iSolutionsNumber += 1;

  16:     }

  17:     Console.WriteLine("It has been extracted {0} solutions from the farm", iSolutionsNumber);

  18:  

  19:  

  20: }

As a result you will get:

  • On the one hand, you will see all the solutions extracted in the output window.
  • On the other hand, you will have all the solutions physical saved in the server drive.
image_thumb image_thumb[1]

References

SharePoint 2013: Como extraer todos los WSPs de una granja!

Pues de nuevo aquí me tenéis hablando sobre este tema del que ya escribí un artículo hace tiempo. Revisando dicho artículo, me di cuenta de que la forma en la que extraía las soluciones ya no era válida para SharePoint 2013. Por suerte, rápidamente descubrí una forma alternativa que os comparto en este artículo. Como podéis ver, la idea pasa por acceder a la colección de soluciones de la granja mediante un objeto de tipo SPSolutionCollection, recorrer la colección e ir guardando los .WSPs en disco.

   1: static void ExtractAllWSPs_2()

   2: { 

   3:     SPFarm spfFarm=SPWebService.ContentService.Farm;

   4:     int iSolutionsNumber = 0;

   5:     SPSolutionCollection spsFarmSolutions=

   6:         spfFarm.Solutions;

   7:     Console.WriteLine("Starting the extraction process...");

   8:     Console.WriteLine("The number of solutions found is {0}",

   9:     spsFarmSolutions.Count);

  10:         

  11:     foreach (SPSolution spfSolution in spsFarmSolutions)

  12:     {

  13:         Console.WriteLine("Extracting solutiin {0}", spfSolution.DisplayName);

  14:         spfSolution.SolutionFile.SaveAs(spfSolution.DisplayName);

  15:         iSolutionsNumber += 1;

  16:     }

  17:     Console.WriteLine("It has been extracted {0} solutions from the farm", iSolutionsNumber);

  18:  

  19:  

  20: }

Como resultado:

  • Por pantalla se muestran las soluciones extraídas.
  • Y por supuesto, podemos comprobar como físicamente dichas soluciones aparecen en la ruta correspondiente.
image image

Referencia: