Convert Your Sitefinity Website to Use NuGet Packages

July 17, 2018 Digital Experience, Sitefinity

To start using NuGet Packages in your Sitefinity CMS projects, you need to install the Telerik.Sitefinity.All NuGet package with the respective version of your project. After the installation is complete, your project will automatically have the following modifications: 

 
  • New packages.config file that contains the list of packages referenced by the project.

  • New ~/packages folder that contains all the NuGet packages used by the project. 

  • The references in your SitefinityWebApp.csprojprovided by default with the Sitefinity CMS Project Manager are replaced with references from the NuGet packages folder:

    • Project Manager Reference:
      <HintPath>bin\Telerik.Sitefinity.dll</HintPath>
    • NuGet Reference:
      <Reference Include="Telerik.Sitefinity, Version=11.0.6700.0, Culture=neutral, PublicKeyToken=b28c218413bdf563, processorArchitecture=MSIL">     <HintPath>packages\Telerik.Sitefinity.Core.11.0.6700\lib\net471\Telerik.Sitefinity.dll</HintPath>
      </Reference>
  •  

Prerequisites  

As Sitefinity CMS has its own public feed for NuGet packages, you need to add it in the NuGet Package Manager Settings with the highest priority. 

To do so, perform the following in Visual Studio: 

  1. In the toolbar, navigate to Tools » NuGet Package Manager » Package Manager Settings » NuGet Package Manager » Package Sources.

  2. Add a new Sitefinity NuGet source by clicking the plus button. 

    1. Name: Sitefinity Nuget 

    2. Source: http://nuget.sitefinity.com/nuget 

  3. If not already present, add a new source with the official NuGet package repository

    1. Name: NuGet Official Package Source  

    2. Source: https://nuget.org/api/v2/  

  4. Make sure that the NuGet Official Package Source is above the Sitefinity NuGet source.


  5. Click OK 

Install NuGet 

To install the Sitefinity NuGet packages, you can use NuGet with either Package Manager UI or Package Manager Console in Visual Studio. The following sections provide steps for how to install NuGet packages with either one of the options. 

Install NuGet Packages via the Package Manager UI 

The following steps are valid for Visual Studio 2015 and 2017.

In Visual Studio, perform the following: 

  1. In the Solution Explorer, right click on your solution and select Manage NuGet Packages for Solution 

  2. Open the Browse tab page and search for Telerik.Sitefinity.All 

  3. From the search results list, select the Telerik.Sitefinity.All package 

  4. On the right, you can specify options for the NuGet package before installing it, such as version, authors, license and dependencies of the package 

  5. Select the project where you want the NuGet package to be installed 

6. Click Install and wait for NuGet to resolve the dependencies of the package.

7. Review the license of the packages and wait until the packages are installed.

8. Build your solution.

Install NuGet Packages via the Package Manager Console 

In the toolbar, navigate to Tools » NuGet Package Manager » Package Manager Console. 

  1. In Package source, select Sitefinity NuGet feed 

  2. In Default project, select the empty project that you created 

  3. In the console, enter Install-Package Telerik.Sitefinity.All -Version 11.0.6700.0 

4. Wait until Sitefinity CMS is installed on your empty project.

5. Build your solution.

Congratulations, you are now using NuGet packages! 

Enable Package Restore (Optional) 

To have a cleaner developer environment and a smaller project size for your Source Control, you can configure the NuGet Package Restore. Package restore ensures all project dependencies are available without storing those packages in the source control. To see a list with the Source Control Management Solution versions, see Omitting NuGet packages in source control systems. NuGet keeps its packages in a local cache on your machine and the next time a missing package is detected, NuGet searches the Cache folder first before downloading another package from the internet. For more information, see Managing the Global Packages, Cache and Temp folders. 

You can enable Package Restore directly from Visual Studio. To do so, navigate to Tools -> Options -> NuGet Package Manager -> General and select the following checkboxes: 

  • Allow NuGet to download missing packages. 

  • Automatically check for missing packages during build in Visual Studio. 

 

 

Using NuGet Packages in Multiple Projects 

If you happen to use multiple Sitefinity CMS instances and upgrading projects one at a time is not your thing, you can update them all at once using NuGet packages from a single Visual Studio Instance. 

All you need to do is include your Sitefinity projects in a single solution and update the NuGet packages. The diagram below illustrates the Bulk Update Process from the Package Manager UI. 

For the Package Manager Console, you have to specify each project where you want NuGet packages to be updated by using the following command: 

Get-Project SitefinityWebApp1, SitefinityWebApp2, SitefinityWebApp3 | Update-Package Telerik.Sitefinity.All -Version 11.0.6700.0 

Further Sitefinity Updates 

From now on, your project is using NuGet packages and the upgrades will be easy. You won’t need the Sitefinity Project Manager to do this or add references manually. For more information on how to upgrade to the next Sitefinity version with click of a button, check out our other blog post—NuGet Packages: The Recommended Way to Upgrade Sitefinity CMS Websites

 

The Progress Team