Skip to content

Instantly share code, notes, and snippets.

@hishaamn
Created July 14, 2024 09:16
Show Gist options
  • Save hishaamn/dad71953fb809a1245fc48c8a51edb24 to your computer and use it in GitHub Desktop.
Save hishaamn/dad71953fb809a1245fc48c8a51edb24 to your computer and use it in GitHub Desktop.
using Sitecore.Install.Framework;
using Sitecore.Diagnostics;
using Sitecore.IO;
using System.Linq;
public class CustomPackageInstallationProcessor : IItemInstallerEvents
{
public void OnItemInstalling(object sender, InstallerEventArgs args)
{
Assert.ArgumentNotNull(sender, nameof(sender));
Assert.ArgumentNotNull(args, nameof(args));
var installationContext = args.InstallArgs.InstallationContext;
var packageItems = installationContext.Items;
foreach (var item in packageItems)
{
// Custom logic to decide if a file should be installed
if (ShouldSkipItem(item))
{
Log.Info($"Skipping installation of item: {item.Name}", this);
installationContext.Items.Remove(item);
}
}
}
private bool ShouldSkipItem(InstallerItem item)
{
// Define your criteria for skipping files here
// For example, skip files based on file extension or name pattern
var skipExtensions = new[] { ".config", ".txt" };
var fileName = FileUtil.GetFileName(item.Name);
return skipExtensions.Any(ext => fileName.EndsWith(ext, System.StringComparison.OrdinalIgnoreCase));
}
// Other interface methods (OnItemInstalled, OnItemUninstalling, etc.) can be left empty or implemented as needed
public void OnItemInstalled(object sender, InstallerEventArgs args) { }
public void OnItemUninstalling(object sender, InstallerEventArgs args) { }
public void OnItemUninstalled(object sender, InstallerEventArgs args) { }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment