If you are working on a Sitecore solution, you will end up referring Sitecore assemblies in your solution. When you deploy your solution to a higher environment or publish it to local Sitecore instance, the Sitecore assemblies referred in solution also gets deployed/published. This creates following problems -
- chances of accidentally overwriting out of box Sitecore assemblies and breaking your Sitecore instance
- increased size of your deployment artifacts
So how do you exclude Sitecore-provided assemblies when you build solutions??
The sc-packages NuGet feed includes version-specific packages that you can use to easily validate or exclude Sitecore-provided assemblies when you build solutions. You can use the below command to check these assemblies -
nuget list Sitecore.Assemblies -Source https://nuget.sitecore.com/resources/v3/index.json -AllVersions
How does it work?
You can use custom MSBuild logic to exclude Sitecore-provided assemblies from publishing. All you have to do is to install NuGet for Sitecore assemblies that you feel are useful in your case. Below is the list of NuGets from Sitecore to identify/list Sitecore assemblices -
Sitecore.Assemblies.Platform
| 9.0+ | All roles based on the the main Sitecore platform (CM, CD, Reporting, and so on). |
Sitecore.Assemblies.XConnect.Web
| 9.0+ | The primary XConnect (Collection) role. |
Sitecore.Assemblies.XConnect.IndexWorker
| 9.0+ | The XConnect search indexer role. |
Sitecore.Assemblies.XConnect.MarketingAutomationEngine
| 9.0+ | The XConnect Marketing Automation Engine processing role. |
Sitecore.Assemblies.XConnect.ProcessingEngine
| 9.1+ | The Sitecore Cortex™ data processing role. |
Sitecore.Assemblies.SitecoreHeadlessServicesServer
| 17.0.0+ | The Sitecore Headless Services. |
Sitecore.Assemblies.SitecoreExperienceAccelerator
| 10.0.1+ | The Sitecore Experience Accelerator role. |
Next, you have to create/update your publish project's .wpp.targets file to exclude files from deployment. Your .wpp.targets file should have below-
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Delay evaluating this item group to ensure nuget package has been evaluated. -->
<Target Name="ExcludeSitecoreAssemblies" AfterTargets="Compile">
<ItemGroup>
<ExcludeFromPackageFiles Include="@(SitecoreAssemblies -> 'bin\%(Filename)%(Extension)')" />
<ExcludeFromPackageFiles Include="@(SitecoreAssemblies -> 'bin\%(Filename).pdb')" />
<ExcludeFromPackageFiles Include="@(SitecoreAssemblies -> 'bin\%(Filename).xml')" />
</ItemGroup>
</Target>
</Project>
Now, when you will publish/deploy your solution, you will find that Sitecore assemblies are not part of your package anymore. It is this simple :)
Hope it helps you!!