public Solution CloneSolution(string uniqueName, string versionNumber, string displayName) { using (var context = new CIContext(OrganizationService)) { var solution = (from sol in context.SolutionSet where sol.UniqueName == uniqueName select new Solution { Version = sol.Version, FriendlyName = sol.FriendlyName }).FirstOrDefault(); if (solution == null || string.IsNullOrEmpty(solution.Version)) { throw new Exception(string.Format("Parent solution with unique name {0} not found.", uniqueName)); } if (string.IsNullOrEmpty(versionNumber)) { Logger.LogVerbose("VersionNumber not supplied. Generating default VersionNumber"); string[] versions = solution.Version.Split('.'); char dot = '.'; versionNumber = string.Concat(versions[0], dot, Convert.ToInt32(versions[1]) + 1, dot, versions[2], dot, versions[3]); Logger.LogVerbose("New version number {0}", versionNumber); } if (string.IsNullOrEmpty(displayName)) { Logger.LogVerbose("displayName not supplied. Generating default displayName"); displayName = solution.FriendlyName; } var cloneAsPatch = new CloneAsSolutionRequest { DisplayName = displayName, ParentSolutionUniqueName = uniqueName, VersionNumber = versionNumber, }; CloneAsSolutionResponse response = OrganizationService.Execute(cloneAsPatch) as CloneAsSolutionResponse; Logger.LogInformation("Clone solution created with Id {0}", response.SolutionId); Solution clone = GetSolution(response.SolutionId, new ColumnSet(true)); Logger.LogInformation("Clone solution name: {0}", clone.UniqueName); return(clone); } }
private static void CloneAsUpgrade(IOrganizationService organizationService, Entity solution) { string currentVersion = solution.GetAttributeValue <string>("version"); string version = VersionNumberUtil.PromptIncrementMajorOrMinor(currentVersion); // Create patch CloneAsSolutionRequest cloneRequest = new CloneAsSolutionRequest(); cloneRequest.DisplayName = solution.GetAttributeValue <string>("friendlyname"); cloneRequest.ParentSolutionUniqueName = solution.GetAttributeValue <string>("uniquename"); cloneRequest.VersionNumber = version; CloneAsSolutionResponse cloneResponse = (CloneAsSolutionResponse)organizationService.Execute(cloneRequest); Console.WriteLine($"Upgraded solution {cloneRequest.DisplayName}"); }