我想在CRM 2016中以编程方式导入解决方案时捕获所有警告。在响应对象中,我没有得到任何此类信息

时间:2016-10-03 14:20:36

标签: dynamics-crm-2013

var importSolutionRequest = new ImportSolutionRequest
            {
                ImportJobId = Guid.NewGuid(),
                CustomizationFile = fileBytes,
                OverwriteUnmanagedCustomizations = true,
                PublishWorkflows = true,
                SkipProductUpdateDependencies = true,
            };
var response =  (ImportSolutionResponse)Service.Execute(importSolutionRequest);

我没有在此响应对象中获得任何有用的信息。我应该做些什么更改才能在导入解决方案时出现此对象中的警告?

1 个答案:

答案 0 :(得分:1)

您必须查询ImportJob才能获得所需的结果(https://msdn.microsoft.com/en-us/library/gg327847.aspx)。

从SDK(https://msdn.microsoft.com/en-us/library/gg509050.aspx):

                // Monitor import success
                byte[] fileBytesWithMonitoring = File.ReadAllBytes(ManagedSolutionLocation);

                ImportSolutionRequest impSolReqWithMonitoring = new ImportSolutionRequest()
                {
                    CustomizationFile = fileBytes,
                    ImportJobId = Guid.NewGuid()
                };

                _serviceProxy.Execute(impSolReqWithMonitoring);
                Console.WriteLine("Imported Solution with Monitoring from {0}", ManagedSolutionLocation);

                ImportJob job = (ImportJob)_serviceProxy.Retrieve(ImportJob.EntityLogicalName, impSolReqWithMonitoring.ImportJobId, new ColumnSet(new System.String[] { "data", "solutionname" }));


                System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
                doc.LoadXml(job.Data);

                String ImportedSolutionName = doc.SelectSingleNode("//solutionManifest/UniqueName").InnerText;
                String SolutionImportResult = doc.SelectSingleNode("//solutionManifest/result/@result").Value;

                Console.WriteLine("Report from the ImportJob data");
                Console.WriteLine("Solution Unique name: {0}", ImportedSolutionName);
                Console.WriteLine("Solution Import Result: {0}", SolutionImportResult);
                Console.WriteLine("");

                // This code displays the results for Global Option sets installed as part of a solution.

                System.Xml.XmlNodeList optionSets = doc.SelectNodes("//optionSets/optionSet");
                foreach (System.Xml.XmlNode node in optionSets)
                {
                    string OptionSetName = node.Attributes["LocalizedName"].Value;
                    string result = node.FirstChild.Attributes["result"].Value;

                    if (result == "success")
                    {
                        Console.WriteLine("{0} result: {1}",OptionSetName, result);
                    }
                    else
                    {
                        string errorCode = node.FirstChild.Attributes["errorcode"].Value;
                        string errorText = node.FirstChild.Attributes["errortext"].Value;

                        Console.WriteLine("{0} result: {1} Code: {2} Description: {3}",OptionSetName, result, errorCode, errorText);
                    }
                }