diff --git a/spkl/SparkleXrm.Tasks/PluginRegistraton.cs b/spkl/SparkleXrm.Tasks/PluginRegistraton.cs index 8359c50..640aae8 100644 --- a/spkl/SparkleXrm.Tasks/PluginRegistraton.cs +++ b/spkl/SparkleXrm.Tasks/PluginRegistraton.cs @@ -30,10 +30,10 @@ public PluginRegistraton(IOrganizationService service, OrganizationServiceContex /// public string SolutionUniqueName { get; set; } - public void RegisterWorkflowActivities(string path) + public void RegisterWorkflowActivities(string path, string publisherPrefix = "") { var assemblyFilePath = new FileInfo(path); - if (Reflection.IgnoredAssemblies.Contains(assemblyFilePath.Name)) + if (Reflection.IgnoreAssembly(assemblyFilePath, publisherPrefix)) return; // Load each assembly Assembly assembly = Reflection.LoadAssembly(assemblyFilePath.FullName); @@ -148,11 +148,11 @@ private void AddStepToSolution(string solutionName, SdkMessageProcessingStep sdk _service.Execute(addToSolution); } - public void RegisterPlugin(string file, bool excludePluginSteps = false) + public void RegisterPlugin(string file, bool excludePluginSteps = false, string publisherPrefix = "") { var assemblyFilePath = new FileInfo(file); - if (assemblyFilePath.Name.StartsWith("System.") || Reflection.IgnoredAssemblies.Contains(assemblyFilePath.Name)) + if (Reflection.IgnoreAssembly(assemblyFilePath, publisherPrefix)) return; // Load each assembly diff --git a/spkl/SparkleXrm.Tasks/Reflection.cs b/spkl/SparkleXrm.Tasks/Reflection.cs index c2d2520..8d02e23 100644 --- a/spkl/SparkleXrm.Tasks/Reflection.cs +++ b/spkl/SparkleXrm.Tasks/Reflection.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Reflection; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; namespace SparkleXrm.Tasks @@ -28,6 +29,8 @@ public class Reflection "Microsoft.Rest.ClientRuntime.dll" }; + private static Regex _ignoredPublisherRegEx = new Regex("^system|microsoft|newtonsoft|sparklexrm.*/.dll"); + public static Assembly LoadAssembly(string path) { Assembly assembly = null; @@ -43,6 +46,26 @@ public static Assembly LoadAssembly(string path) return assembly; } + public static bool IgnoreAssembly(FileInfo assemblyFilePath, string publisherPrefix = "", bool onlyPublisherAssemblies = false) + { + var assemblyName = assemblyFilePath.Name.ToLower(); + + // if publisher prefix is specified we consider assemblies starting with this prefix OK to deploy + if (!string.IsNullOrEmpty(publisherPrefix)) + { + if (assemblyName.StartsWith(publisherPrefix.ToLower())) + { + return false; + } + else if (onlyPublisherAssemblies) + { + return true; // ignore other assemblies if the corresponding flag is raised + } + } + + return _ignoredPublisherRegEx.IsMatch(assemblyName); + } + public static IEnumerable GetTypesImplementingInterface(Assembly assembly, Type interfaceName) { var types = assembly.ExportedTypes.Where(p => p.GetInterfaces().FirstOrDefault(a => a.Name == interfaceName.Name) != null); diff --git a/spkl/SparkleXrm.Tasks/Tasks/DeployPluginsTask.cs b/spkl/SparkleXrm.Tasks/Tasks/DeployPluginsTask.cs index 77c96dc..b6676a2 100644 --- a/spkl/SparkleXrm.Tasks/Tasks/DeployPluginsTask.cs +++ b/spkl/SparkleXrm.Tasks/Tasks/DeployPluginsTask.cs @@ -16,6 +16,8 @@ public class DeployPluginsTask : BaseTask { public bool ExcludePluginSteps { get; set; } + public string PublisherPrefix { get; set; } + public DeployPluginsTask(IOrganizationService service, ITrace trace) : base(service, trace) { @@ -57,7 +59,7 @@ private void DeployPlugins(OrganizationServiceContext ctx, ConfigFile config) { try { - pluginRegistration.RegisterPlugin(assemblyFilePath, ExcludePluginSteps); + pluginRegistration.RegisterPlugin(assemblyFilePath, ExcludePluginSteps, PublisherPrefix); } catch (ReflectionTypeLoadException ex) diff --git a/spkl/SparkleXrm.Tasks/Tasks/DeployWorkflowActivitiesTask.cs b/spkl/SparkleXrm.Tasks/Tasks/DeployWorkflowActivitiesTask.cs index 51019cd..ec1af5b 100644 --- a/spkl/SparkleXrm.Tasks/Tasks/DeployWorkflowActivitiesTask.cs +++ b/spkl/SparkleXrm.Tasks/Tasks/DeployWorkflowActivitiesTask.cs @@ -13,6 +13,8 @@ namespace SparkleXrm.Tasks { public class DeployWorkflowActivitiesTask : BaseTask { + public string PublisherPrefix { get; set; } + public DeployWorkflowActivitiesTask(IOrganizationService service, ITrace trace) : base(service, trace) { } @@ -49,7 +51,7 @@ private void DeployWorkflowActivities(OrganizationServiceContext ctx, ConfigFile { try { - pluginRegistration.RegisterWorkflowActivities(assemblyFilePath); + pluginRegistration.RegisterWorkflowActivities(assemblyFilePath, PublisherPrefix); } catch (ReflectionTypeLoadException ex) { diff --git a/spkl/spkl/Program.cs b/spkl/spkl/Program.cs index f314b44..65e23af 100644 --- a/spkl/spkl/Program.cs +++ b/spkl/spkl/Program.cs @@ -325,12 +325,18 @@ private static void RunTask(CommandLineArgs arguments, IOrganizationService serv case "plugins": trace.WriteLine("Deploying Plugins"); task = new DeployPluginsTask(service, trace) - { ExcludePluginSteps = arguments.ExcludePluginSteps }; + { + ExcludePluginSteps = arguments.ExcludePluginSteps, + PublisherPrefix = arguments.Prefix + }; break; case "workflow": trace.WriteLine("Deploying Custom Workflow Activities"); - task = new DeployWorkflowActivitiesTask(service, trace); + task = new DeployWorkflowActivitiesTask(service, trace) + { + PublisherPrefix = arguments.Prefix + }; break; case "webresources":