My Sitecore Upgrade Learnings Part 2

Hello Everyone, This is second part of  My Sitecore Upgrade Learnings. In previous part we have seen, how to upgrade Sitecore from one version to another. You can refer the same in link Part1.

In this blog, we will try to cover the backend code part upgrade required for the same. There are many ways in which we can upgrade the code part listed below.
  • Updating the Sitecore DLL using Package Manager Console for all the projects in your current solution
  • Using a Powershell Script to update the Sitecore DLL for all the projects in your current solution

The First option is fairly simple. Open any project of your solution, Click on references --> Manage Nuget Package. Once Nuget Package is open, then you will see the installed version of Sitecore DLL. Click on Update tab and you will be able to see the updated version. Just select the version as per your need and click on update. It will also update all the dependent DLL for that version. There is one more option to update the Sitecore package for all the projects in your solution. You can check the checkbox of the project where the upgrade is required. Refer below screenshot for reference


The second option is to update the Sitecore package from Package Manager console using below script. The first script removes the NoReference packages from all the projects. The second script update the target version of Sitecore dll and Sitecore framework condition for all projects. For our projects we upgraded to Sitecore 10.2 and Sitecore Framework condition version 5.0.0

       
PM> Write-Host "Installing new packages and removing *.NoReferences packages...\n"; Get-Project -All | ForEach-Object { Get-Package -ProjectName $_.ProjectName } | Where-Object { $_.Id -like 'Sitecore.*' } | ForEach-Object { Uninstall-Package -Id $_.Id -ProjectName $_.ProjectName -Force ; Install-Package -Id $_.Id.Replace('.NoReferences', '') -IgnoreDependencies -ProjectName $_.ProjectName; }

PM> $targetVersions = @('10.2.0','5.0.0'); Get-Project -All | ForEach-Object { Get-Package -ProjectName $_.ProjectName } | Where-Object { $_.Id -like 'Sitecore.*' } | ForEach-Object { if( $targetVersions -notcontains $_.Versions[0] ) { Uninstall-Package -Id $_.Id -ProjectName $_.ProjectName -Force } }
	   
 

There is one more option for upgrade and this is using Package reference instead of Package config. We migrated our package config to package reference as it will save lot of time in future when we have to migrate again from one version to another. As package refernce gives the flexibility to simply update the reference version of the dependent packages in csproj file of the project. Once you update the version and build it, it will auto update you package. No need to spend time on updating your packages from Nuget.
To get more understanding, you can refer the link which state benefits and limitations of using Package reference.

https://learn.microsoft.com/en-us/nuget/consume-packages/migrate-packages-config-to-package-reference

Once you have updated your the references, its time to build your solution and get the errors. Once you solve those errors. You are good to go and deploy your solution to webroot. Before deploying, take backup of your vanila instance webroot.

Below are some issue we encountered. Some where deprecated code and some due to DLL version mismatch issue.

  • After deploying your solution, not able to see Solr schema and indexes : 1. check your solr core configurations. 2. Check your SolrNet dll version with your plain vanila instance SolrNet dll and update it accordingly
  • Face any connection timeout or connection closed issue while doing populate schema : update ContentSearch.Solr.ConnectionTimeout setting in config Sitecore.ContentSearch.Solr.DefaultIndexConfiguration.config. Update the value timeout to "500000" from -1
           
           <setting name="ContentSearch.Solr.ConnectionTimeout" value="500000" />
    	   
     
  • Tracker.Current.Session.IdentifyAs() is not supported in 10.2 :
           
    using Sitecore.Analytics.Tracking.Identification;
    
    private static readonly IContactIdentificationManager _contactIdentificationManager =ServiceLocator.ServiceProvider.GetService<IContactIdentificationManager>();
    
       IdentificationResult result = _contactIdentificationManager.IdentifyAs(
                                        new KnownContactIdentifier({Indentfierkey}, {Identfiervalue}));
    
     
  • Getting contact through XConnect API which uses identifier and Contact Expand option is obsolete : Use below code.
           
    The code of getting contact through XConnect API which uses identifier and Contact Expand option is obsolete.
    contact = xClient.Get<Sitecore.XConnect.Contact>(new Sitecore.XConnect.IdentifiedContactReference({Identfierkey}, {identifiervalue}), new Sitecore.XConnect.ContactExpandOptions(getFacets));
                      
    Use the Contact Execute Options which takes Contact Expand Options as param.        
    var trackerIdentifier = new IdentifiedContactReference(Identfierkey}, {identifiervalue});
                                var contactexpandoption = new ContactExpandOptions(getFacets);
                                contact = xClient.Get<Sitecore.XConnect.Contact>(trackerIdentifier, new ContactExecutionOptions(contactexpandoption));
    	   
     
  • Getting full url with root node in Sitecore --> then check enable preview option setting in Site grouping
  • Any Data provider define in prefetch config, the check once whether it is supported or not. In our case it was not supported and we have to change the provider config.
           
    Old obsolete code
    <dataProvider >                          
      <prefetch role:require="ContentDelivery or Standalone">                              
        <item desc="  ">{{Home Item ID}}</item>                          
      </prefetch>                      
     </dataProvider>                  
    
    New code
    <dataProvider>                 
     <param desc="headProvider">                      
    	<dataProvider ref="dataProviders/main" param1="$(id)">                          
    		<prefetch role:require="ContentDelivery or Standalone">                              
    			<item desc="home">{{Home Item ID}}</item> 
    		</prefetch>                      
    	</dataProvider>                  
     </param>              
    </dataProvider>
    	   
     
  • Using gulp for local deployment and getting this issue after upgrade like "gulp primordials is not defined fs.js" while running local gulp : Update package.config below points before "devDependencies"
           
    "scripts": {    
             "preinstall": "npx npm-force-resolutions",    
    		 "test": "echo \"Error: no test specified\" && exit 1"  
    		 },
    		 "resolutions": {    "graceful-fs": "^4.2.10"  }
    		 
    
    Or Add below line
    
    "overrides": {    "graceful-fs": "^4.2.10"  }
    
    Update below point in gulp-config.js for vs 2019
    buildToolsVersion: '16.0' 
    	   
     

I Hope, this blog will help you in some way. See you next time.

Happy Sitecoring. Happy Learning!!

Few links you can refer during upgrade

  • https://sitecore.myget.org/feed/sc-identity/package/nuget/Sitecore.Framework.Conditions
  • https://sitecore.myget.org/feed/sc-packages/package/nuget/Sitecore
  • https://joaoneto.blog/save-time-updating-sitecore-nuget-packages/

Comments

Popular posts from this blog

Sitecore XM Cloud Form Integration with Azure Function as Webhook

Automate RSS Feed to Sitecore XM Cloud: Logic App, Next.js API & Authoring API Integration

Create and Fetch Content From Sitecore Content Hub One using GraphQL and React