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

  • Danial47 Profile Picture
    142 on at
    RE: Is there a way to Retrieve, Export (or Package) a Solution in code ?

    Hi jhon

    Could you please to explain more about your code?

    how to run the code?

    is it a DLL or not?

    Thanks

    BR

  • Community Member Profile Picture
    on at
    RE: Is there a way to Retrieve, Export (or Package) a Solution in code ?

    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();

               }

           }

       }

    }

  • Community Member Profile Picture
    on at
    RE: Is there a way to Retrieve, Export (or Package) a Solution in code ?

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

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: Is there a way to Retrieve, Export (or Package) a Solution in code ?

    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.

  • Suggested answer
    Radu Chiribelea Profile Picture
    6,667 on at
    RE: Is there a way to Retrieve, Export (or Package) a Solution in code ?

    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
    Aric Levin - MVP Profile Picture
    30,188 Moderator on at
    RE: Is there a way to Retrieve, Export (or Package) a Solution in code ?

    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.

  • Community Member Profile Picture
    on at
    RE: Is there a way to Retrieve, Export (or Package) a Solution in code ?

    Thanks.

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

  • Suggested answer
    Radu Chiribelea Profile Picture
    6,667 on at
    RE: Is there a way to Retrieve, Export (or Package) a Solution in code ?

    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

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans