web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Is there a way to Retrieve, Export (or Package) a Solution in code ?

(0) ShareShare
ReportReport
Posted on by

Is there a way to Retrieve, Export (or Package) a Solution in code ?

I´m working with dynamics 2016

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Radu Chiribelea Profile Picture
    6,667 on at

    Hi Jhon,

    You can use the ExportSolutionRequest (msdn.microsoft.com/.../microsoft.crm.sdk.messages.exportsolutionrequest.aspx)

    You can check following sample code provided by MS: msdn.microsoft.com/.../gg509050.aspx

    Regards,

    Radu

  • Community Member Profile Picture
    on at

    Thanks.

    Is there a tool, a web page or a github code that makes it ?

  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    Have used this code for previous project:

    public EntityCollection RetrieveSolutions(string solutionName)

    {

    QueryExpression query = new QueryExpression

    {

    EntityName = "solution",

    ColumnSet = new ColumnSet(true),

    Criteria =

    {

    Conditions =

    {

    new ConditionExpression("uniquename", ConditionOperator.Equal, solutionName)

    },

    }

    };

    RetrieveMultipleRequest request = new RetrieveMultipleRequest();

    request.Query = query;

    try

    {

    RetrieveMultipleResponse response = (RetrieveMultipleResponse)service.Execute(request);

    EntityCollection results = response.EntityCollection;

    return results;

    }

    catch (FaultException<OrganizationServiceFault> ex)

    {

    throw new Exception(ex);

    }

    }

    public bool ImportSolution(string fileName)

    {

    byte[] fileBytes = File.ReadAllBytes(fileName);

    ImportSolutionRequest request = new ImportSolutionRequest()

    {

    CustomizationFile = fileBytes

    };

    try

    {

    ImportSolutionResponse response = (ImportSolutionResponse)service.Execute(request);

    return true;

    }

    catch (FaultException<OrganizationServiceFault> ex)

    {

    throw new Exception(ex);

    }

    }

    Use ExportSolutionRequest to Export a solution.

    Hope this helps.

  • Suggested answer
    Radu Chiribelea Profile Picture
    6,667 on at

    Hi Jhon,

    You can find the sample code in the following location in the download package: www.microsoft.com/.../details.aspx

    SampleCode\CS\Solutions\WorkWithSolutions.cs

    You can modify it to meet your needs and then compile it.

    Hope this helps

    Radu

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hello John,

    Here is the simple article to retrieve solution using c#. You can create console and try.

    jkkdynamiccrm.blogspot.in/.../export-solution-using-c-code-from-ms-crm.html

    Hope this helps.

  • Community Member Profile Picture
    on at

    XrmToolbox has a Solution Packager Plugin available:  www.xrmtoolbox.com/plugins

  • Community Member Profile Picture
    on at

    Thanks to all. I´ve done this code and works.

    using Microsoft.Crm.Sdk.Messages;

    using Microsoft.Xrm.Sdk;

    using Microsoft.Xrm.Sdk.Messages;

    using Microsoft.Xrm.Sdk.Query;

    using Microsoft.Xrm.Sdk.Workflow;

    using System;

    using System.Activities;

    using System.Collections.Generic;

    using System.IO;

    using System.Linq;

    using System.ServiceModel;

    using System.Text;

    namespace DynamicsSolutions.CRMGenericTools.Utilities.General

    {

       class ExportASolution : CodeActivity

       {

           [RequiredArgument]

           [Input("Solution Unique Name")]

           public InArgument<string> SolutionUniqueName { get; set; }

           [RequiredArgument]

           [Input("Place where is the folder on the local PC")]

           public InArgument<string> FolderPlace { get; set; }

           private ITracingService m_tracingService;

           private void Trace(string message)

           {

               if (this.m_tracingService != null)

               {

                   this.m_tracingService.Trace(message);

               }

           }

           protected override void Execute(CodeActivityContext executionContext)

           {

               IWorkflowContext extension1 = executionContext.GetExtension<IWorkflowContext>();

               IOrganizationService organizationService = executionContext.GetExtension<IOrganizationServiceFactory>().CreateOrganizationService(new

                   Guid?(((IExecutionContext)extension1).UserId));

               try

               {

                   this.Run(organizationService,

                       this.SolutionUniqueName.Get(executionContext),

                       this.FolderPlace.Get(executionContext));

               }

               catch (FaultException<OrganizationServiceFault> ex)

               {

                   ex.ToString();

               }

           }

           public void Run(IOrganizationService service,

               string solutionUniqueName,

               string folderPlace)

           {

               try

               {

                   //Export is taking from CRM and saving on the local PC

                   solutionUniqueName.e

                   ExportSolutionRequest exportSolutionRequest = new ExportSolutionRequest();

                   exportSolutionRequest.Managed = false;

                   exportSolutionRequest.SolutionName = solutionUniqueName;

                   ExportSolutionResponse exportSolutionResponse = (ExportSolutionResponse)service.Execute(exportSolutionRequest);

                   byte[] exportXml = exportSolutionResponse.ExportSolutionFile;

                   string filename = solutionUniqueName + ".zip";

                   //string test = "@"" + filename + """;

                   if (Directory.Exists(folderPlace))

                   {

                       File.WriteAllBytes(folderPlace + filename, exportXml);

                   }

                   else

                   {

                       throw new Exception("The folder doesn´t exists");

                   }

               }

               catch (FaultException<OrganizationServiceFault> ex)

               {                

                   ex.ToString();

               }

           }

       }

    }

  • Danial47 Profile Picture
    142 on at

    Hi jhon

    Could you please to explain more about your code?

    how to run the code?

    is it a DLL or not?

    Thanks

    BR

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans