Using package references in your Sitecore Project
Posted in :
Part of the upgrade in a Sitecore project is to remove the package.config file and change the way how we handle all Sitecore references.
So, let’s follow these steps:
- The first step is elementary: remove the packages.config file from your project
- Now, open the Nuget package manager configuration in the Visual Studio options and change the “Package Management” option to “PackageReference”

Ok, so until here isn’t a big deal, right?
So let’s do the following in the project
- Clear the bin folder
- Remove all the references in the reference list, only keep the project references and the third-party references if this is your case.
- Don’t forget to remove all System.* references too.
- Add again the Sitecore references using the “Nuget Package manner” like Sitecore.Kernel; here remember to add the correspondant to your Sitecore instance version.
At this point, you just need to add the Sitecore references specific to your project. e.g:
- Sitecore.Kernel – all base libraries
- Sitecore.MVC – all libraries related to work with Asp.net Mvc with Sitecore
- Sitecre.XConnect – All related to the xDb functionality
- and so on.
Add again the references to System.* libraries like these ones:
- Microsoft.CSharp
- System
- System.Configuration
- System.Web
it should look like this:

Now, Compile your project and review if all the code works similarly before these changes.
You will see again all the dlls in your bin folder, now let’s reduce those files only with the necessary ones.
- Unload your project from the solution, right-click on your project, and choose the unload option

- Find the package references section and add the following in each Sitecore reference
<IncludeAssets>Compile</IncludeAssets>
- Save the project file and reload the project
- Clear again the bin folder
- Recompile your project
You will see a reduced number of dlls copies to the bin directory
And, finally, let’s fix the “web.config” file to have the assembly bindings correctly working
- open the web.config file and JUST comment the <runtime> section.
- re-compile your project
- open the error list window and check the warning list
You’re gonna see a warning like this one:

- Double-click on that one, and then you will see a question message asking to fix the binding records in the web.config file.
- So, click on yes
- Now, all is ready to go and fix.
Don’t forget to remove the comment section in the file.
And that is pretty much it.
Repeat this process in each Sitecore project in your solution
Happy coding! 🙂