private string UnPackSolution(SolutionPackageConfig solutionPackagerConfig, string targetFolder)
        {
            // For the "both" option, SolutionPackager expects the managed and umanaged exports
            // to exist as zip files in the same file folder, and have the same name except that the
            // managed version will have the _managed suffix prior to the .zip extension.
            var tempFilePath             = Path.GetTempFileName();
            var unmanagedSolutionZipPath = tempFilePath.Replace(".tmp", ".zip");
            var managedSolutionZipPath   = tempFilePath.Replace(".tmp", "_managed.zip");

            File.Delete(tempFilePath);

            switch (solutionPackagerConfig.packagetype)
            {
            case PackageType.managed:
                ExportManagedSolution(solutionPackagerConfig, managedSolutionZipPath);
                UnpackSolutionZip(solutionPackagerConfig, targetFolder, managedSolutionZipPath);
                break;

            case PackageType.unmanaged:
                ExportUnmanagedSolution(solutionPackagerConfig, unmanagedSolutionZipPath);
                UnpackSolutionZip(solutionPackagerConfig, targetFolder, unmanagedSolutionZipPath);
                break;

            default:     //both-managed or both-unmanaged
                ExportUnmanagedSolution(solutionPackagerConfig, unmanagedSolutionZipPath);
                ExportManagedSolution(solutionPackagerConfig, managedSolutionZipPath);
                UnpackSolutionZip(solutionPackagerConfig, targetFolder, unmanagedSolutionZipPath);
                break;
            }

            return(targetFolder);
        }
Пример #2
0
        public static void AddOrUpdateSpklMapping(Project project, string profile, SolutionPackageConfig solutionPackageConfig)
        {
            SpklConfig spklConfig = CoreMapping.GetSpklConfigFile(project);

            if (profile.StartsWith(ExtensionConstants.NoProfilesText))
            {
                spklConfig.solutions[0] = solutionPackageConfig;
            }
            else
            {
                SolutionPackageConfig existingSolutionPackageConfig = spklConfig.solutions.FirstOrDefault(s => s.profile == profile);
                if (existingSolutionPackageConfig != null && solutionPackageConfig != null)
                {
                    existingSolutionPackageConfig.increment_on_import = solutionPackageConfig.increment_on_import;
                    existingSolutionPackageConfig.map                 = solutionPackageConfig.map;
                    existingSolutionPackageConfig.packagetype         = solutionPackageConfig.packagetype;
                    existingSolutionPackageConfig.packagepath         = solutionPackageConfig.packagepath.Replace("/", string.Empty);
                    existingSolutionPackageConfig.solution_uniquename = solutionPackageConfig.solution_uniquename;
                    existingSolutionPackageConfig.solutionpath        = FormatSolutionName(solutionPackageConfig.solutionpath);
                }
            }

            string projectPath = CrmDeveloperExtensions2.Core.Vs.ProjectWorker.GetProjectPath(project);

            ConfigFile.UpdateSpklConfigFile(projectPath, spklConfig);
        }
Пример #3
0
        private string PackSolution(string rootPath, SolutionPackageConfig solutionPackagerConfig, string solutionZipPath)
        {
            // Get location of source xml files
            var packageFolder = Path.Combine(rootPath, solutionPackagerConfig.packagepath);

            if (solutionPackagerConfig.increment_on_import)
            {
                var solution = GetSolution(solutionPackagerConfig.solution_uniquename);
                // Increment version in the package to upload
                // We increment the version in CRM already incase the solution package version is not correct
                IncrementVersion(solution.Version, packageFolder);
            }

            var binPath   = GetPackagerFolder();
            var binFolder = new FileInfo(binPath).DirectoryName;

            // Create packager map.xml
            CreateMapFile(solutionPackagerConfig, Path.Combine(binFolder, "packager_map.xml"));

            // Run CrmSvcUtil
            var parameters = String.Format(@"/action:Pack /zipfile:""{0}"" /folder:""{1}"" /packagetype:{2} /errorlevel:Verbose /nologo /log:packagerlog.txt /map:packager_map.xml",
                                           solutionZipPath,
                                           packageFolder,
                                           solutionPackagerConfig.packagetype.ToString()
                                           );

            RunPackager(binPath, binFolder, parameters);

            return(solutionZipPath);
        }
        private void ExportUnmanagedSolution(SolutionPackageConfig config, string filePath)
        {
            var request = new ExportSolutionRequest
            {
                SolutionName = config.solution_uniquename,
                ExportAutoNumberingSettings          = false,
                ExportCalendarSettings               = false,
                ExportCustomizationSettings          = false,
                ExportEmailTrackingSettings          = false,
                ExportExternalApplications           = false,
                ExportGeneralSettings                = false,
                ExportIsvConfig                      = false,
                ExportMarketingSettings              = false,
                ExportOutlookSynchronizationSettings = false,
                ExportRelationshipRoles              = false,
                ExportSales = false,
                Managed     = false
            };

            var response = (ExportSolutionResponse)_service.Execute(request);

            // Save solution
            using (var fs = File.Create(filePath))
            {
                fs.Write(response.ExportSolutionFile, 0, response.ExportSolutionFile.Length);
            }
        }
Пример #5
0
        private string UnPackSolution(SolutionPackageConfig solutionPackagerConfig, string targetFolder)
        {
            // Extract solution
            var request = new ExportSolutionRequest
            {
                SolutionName = solutionPackagerConfig.solution_uniquename,
                ExportAutoNumberingSettings          = false,
                ExportCalendarSettings               = false,
                ExportCustomizationSettings          = false,
                ExportEmailTrackingSettings          = false,
                ExportExternalApplications           = false,
                ExportGeneralSettings                = false,
                ExportIsvConfig                      = false,
                ExportMarketingSettings              = false,
                ExportOutlookSynchronizationSettings = false,
                ExportRelationshipRoles              = false,
                ExportSales = false,
                Managed     = solutionPackagerConfig.packagetype == PackageType.managed
            };

            var response = (ExportSolutionResponse)_service.Execute(request);

            // Save solution
            var solutionZipPath = Path.GetTempFileName();

            File.WriteAllBytes(solutionZipPath, response.ExportSolutionFile);

            UnpackSolutionZip(solutionPackagerConfig, targetFolder, solutionZipPath);

            return(targetFolder);
        }
Пример #6
0
        public static void Create(SolutionPackageConfig solutionPackageConfig, string path)
        {
            // Create mapping xml with relative paths

            /*
             * <?xml version="1.0" encoding="utf-8"?>
             * <Mapping>
             *  <!-- Match specific named files to an alternate folder -->
             *  <!--<FileToFile map="Plugins.dll" to="..\..\Plugins\bin\**\Plugins.dll" />
             *  <FileToFile map="CRMDevTookitSampleWorkflow.dll" to="..\..\Workflow\bin\**\CRMDevTookitSample.Workflow.dll" />-->
             *  <!-- Match any file in and under WebResources to an alternate set of sub-folders -->
             *  <FileToPath map="PluginAssemblies\**\*.*" to="..\..\Plugins\bin\**" />
             *  <FileToPath map="WebResources\*.*" to="..\..\Webresources\Webresources\**" />
             *  <FileToPath map="WebResources\**\*.*" to="..\..\Webresources\Webresources\**" />
             * </Mapping>
             */

            var mappingDoc = new XDocument();
            var mappings   = new XElement("Mapping");

            mappingDoc.Add(mappings);

            foreach (var map in solutionPackageConfig.map)
            {
                if (map.map == MapTypes.file.ToString())
                {
                    mappings.Add(new XElement("FileToFile",
                                              new XAttribute("map", map.from),
                                              new XAttribute("to", map.to)));
                }

                if (map.map == MapTypes.folder.ToString())
                {
                    mappings.Add(new XElement("Folder",
                                              new XAttribute("map", map.from),
                                              new XAttribute("to", map.to)));
                }

                if (map.map == MapTypes.path.ToString())
                {
                    mappings.Add(new XElement("FileToPath",
                                              new XAttribute("map", map.from),
                                              new XAttribute("to", map.to)));
                }
            }

            string mapContent = mappingDoc.ToString();

            if (string.IsNullOrEmpty(mapContent))
            {
                return;
            }

            File.WriteAllText(path, mapContent);
        }
        private void CreateMapFile(SolutionPackageConfig packConfig, string path)
        {
            // Create mapping xml with relative paths

            /*
             * <?xml version="1.0" encoding="utf-8"?>
             * <Mapping>
             *  <!-- Match specific named files to an alternate folder -->
             *  <!--<FileToFile map="Plugins.dll" to="..\..\Plugins\bin\**\Plugins.dll" />
             *  <FileToFile map="CRMDevTookitSampleWorkflow.dll" to="..\..\Workflow\bin\**\CRMDevTookitSample.Workflow.dll" />-->
             *  <!-- Match any file in and under WebResources to an alternate set of sub-folders -->
             *  <FileToPath map="PluginAssemblies\**\*.*" to="..\..\Plugins\bin\**" />
             *  <FileToPath map="WebResources\*.*" to="..\..\Webresources\Webresources\**" />
             *  <FileToPath map="WebResources\**\*.*" to="..\..\Webresources\Webresources\**" />
             * </Mapping>
             */
            var mappingDoc = new XDocument();
            var mappings   = new XElement("Mapping");

            mappingDoc.Add(mappings);

            if (packConfig != null && packConfig.map != null)
            {
                foreach (var map in packConfig.map)
                {
                    switch (map.map)
                    {
                    case MapTypes.file:
                        mappings.Add(new XElement("FileToFile",
                                                  new XAttribute("map", map.from),
                                                  new XAttribute("to", map.to)));
                        break;

                    case MapTypes.folder:
                        mappings.Add(new XElement("Folder",
                                                  new XAttribute("map", map.from),
                                                  new XAttribute("to", map.to)));
                        break;

                    case MapTypes.path:
                        mappings.Add(new XElement("FileToPath",
                                                  new XAttribute("map", map.from),
                                                  new XAttribute("to", map.to)));
                        break;
                    }
                }
            }
            else
            {
                _trace.WriteLine("No file mappings found in spkl.json");
            }
            _trace.WriteLine("Map xml created at '{0}'", path);
            File.WriteAllText(path, mappingDoc.ToString());
        }
Пример #8
0
        public static SolutionPackageConfig GetSolutionPackageConfig(Project project, string profile, ObservableCollection <CrmSolution> crmSolutions)
        {
            SpklConfig spklConfig = CoreMapping.GetSpklConfigFile(project);

            List <SolutionPackageConfig> spklSolutionPackageConfigs = spklConfig.solutions;

            if (spklSolutionPackageConfigs == null)
            {
                return(null);
            }

            SolutionPackageConfig solutionPackageConfig = profile.StartsWith(ExtensionConstants.NoProfilesText)
                ? spklSolutionPackageConfigs[0]
                : spklSolutionPackageConfigs.FirstOrDefault(p => p.profile == profile);

            return(solutionPackageConfig);
        }
        private string GetSolutionZipFileName(ConfigFile config, SolutionPackageConfig solutionPackagerConfig, Version version)
        {
            var solutionZipPath = "solution.zip";

            // Create the solution zip in the root or the location specified in the spkl.json
            if (solutionPackagerConfig.solutionpath != null)
            {
                solutionZipPath = String.Format(solutionPackagerConfig.solutionpath,
                                                version.Major,
                                                version.Minor > -1 ? version.Minor : 0,
                                                version.Build > -1 ? version.Build : 0,
                                                version.Revision > -1 ? version.Revision : 0);
            }

            solutionZipPath = Path.Combine(config.filePath, solutionZipPath);
            return(solutionZipPath);
        }
Пример #10
0
        private void UnpackSolutionZip(SolutionPackageConfig solutionPackagerConfig, string targetFolder, string solutionZipPath)
        {
            var binPath   = GetPackagerFolder();
            var binFolder = new FileInfo(binPath).DirectoryName;

            // Create packager map.xml
            CreateMapFile(solutionPackagerConfig, Path.Combine(binFolder, "packager_map.xml"));

            // Run CrmSvcUtil
            var parameters = String.Format(@"/action:Extract /zipfile:""{0}"" /folder:""{1}"" /packagetype:{2} /allowWrite:Yes /allowDelete:Yes /clobber /errorlevel:Verbose /nologo /log:packagerlog.txt /map:packager_map.xml",
                                           solutionZipPath,
                                           targetFolder,
                                           solutionPackagerConfig.packagetype.ToString()
                                           );

            RunPackager(binPath, binFolder, parameters);
        }
Пример #11
0
        private string UnPackSolution(SolutionPackageConfig solutionPackagerConfig, string targetFolder)
        {
            // Extract solution
            var request = new ExportSolutionRequest
            {
                SolutionName = solutionPackagerConfig.solution_uniquename,
                ExportAutoNumberingSettings          = false,
                ExportCalendarSettings               = false,
                ExportCustomizationSettings          = false,
                ExportEmailTrackingSettings          = false,
                ExportExternalApplications           = false,
                ExportGeneralSettings                = false,
                ExportIsvConfig                      = false,
                ExportMarketingSettings              = false,
                ExportOutlookSynchronizationSettings = false,
                ExportRelationshipRoles              = false,
                ExportSales = false,
                Managed     = false
            };

            var response = (ExportSolutionResponse)_service.Execute(request);

            // Save solution
            var solutionZipPath = Path.GetTempFileName();

            File.WriteAllBytes(solutionZipPath, response.ExportSolutionFile);

            var binPath   = GetPackagerFolder();
            var binFolder = new FileInfo(binPath).DirectoryName;

            // Create packager map.xml
            CreateMapFile(solutionPackagerConfig, Path.Combine(binFolder, "packager_map.xml"));

            // Run CrmSvcUtil
            var parameters = String.Format(@"/action:Extract /zipfile:""{0}"" /folder:""{1}"" /packagetype:{2} /allowWrite:Yes /allowDelete:Yes /clobber /errorlevel:Verbose /nologo /log:packagerlog.txt /map:packager_map.xml",
                                           solutionZipPath,
                                           targetFolder,
                                           solutionPackagerConfig.packagetype.ToString()
                                           );

            RunPackager(binPath, binFolder, parameters);

            return(targetFolder);
        }
Пример #12
0
        private void UnpackSolutionZip(SolutionPackageConfig solutionPackagerConfig, string targetFolder, string solutionZipPath)
        {
            var binPath = GetPackagerFolder();
            var binFolder = new FileInfo(binPath).DirectoryName;

            // Create packager map.xml
            CreateMapFile(solutionPackagerConfig, Path.Combine(binFolder, "packager_map.xml"));

            // Run CrmSvcUtil 
            var parameters = String.Format(@"/action:Extract /zipfile:""{0}"" /folder:""{1}"" /packagetype:{2} /allowWrite:{3} /allowDelete:{4} /errorlevel:Verbose /nologo /log:packagerlog.txt /map:packager_map.xml{5}",
                solutionZipPath,
                targetFolder,
                (solutionPackagerConfig.packagetype == PackageType.both_unmanaged_import 
                  || solutionPackagerConfig.packagetype == PackageType.both_managed_import) ? "both" : solutionPackagerConfig.packagetype.ToString(),
                solutionPackagerConfig.allowwrite == false ? "No" : "Yes",
                solutionPackagerConfig.allowdelete == false ? "No" : "Yes",
                solutionPackagerConfig.clobber == false ? "" : " /clobber");

            RunPackager(binPath, binFolder, parameters);
        }
        private string PackSolution(string rootPath, SolutionPackageConfig solutionPackagerConfig, string solutionZipPath)
        {
            // Get location of source xml files
            var packageFolder = Path.Combine(rootPath, solutionPackagerConfig.packagepath);

            if (solutionPackagerConfig.increment_on_import)
            {
                var solution = GetSolution(solutionPackagerConfig.solution_uniquename);
                // Increment version in the package to upload
                // We increment the version in CRM already incase the solution package version is not correct
                IncrementVersion(solution.Version, packageFolder);
            }

            var binPath   = GetPackagerFolder();
            var binFolder = new FileInfo(binPath).DirectoryName;

            // Create packager map.xml
            CreateMapFile(solutionPackagerConfig, Path.Combine(binFolder, "packager_map.xml"));

            // Run CrmSvcUtil
            var parameters = String.Format(@"/action:Pack /zipfile:""{0}"" /folder:""{1}"" /packagetype:{2} /errorlevel:Verbose /nologo /log:packagerlog.txt /map:packager_map.xml",
                                           solutionZipPath,
                                           packageFolder,
                                           (solutionPackagerConfig.packagetype == PackageType.both_unmanaged_import ||
                                            solutionPackagerConfig.packagetype == PackageType.both_managed_import) ? "both" : solutionPackagerConfig.packagetype.ToString()
                                           );

            RunPackager(binPath, binFolder, parameters);

            // When package type is both_managed_import then SolutionPackager will create
            // two zip files. Need to pass back the name of the he managed version which
            // has "_managed" in the name right before the .zip extension.
            if (solutionPackagerConfig.packagetype == PackageType.both_managed_import)
            {
                return(solutionZipPath.Replace(".zip", "_managed.zip"));
            }

            return(solutionZipPath);
        }