Work with solutions
Updated: November 29, 2016
Applies To: Dynamics 365 (online), Dynamics 365 (on-premises), Dynamics CRM 2016, Dynamics CRM Online
This topic presents specific programming tasks included in Sample: Work with solutions and Sample: Detect solution dependencies.
Every solution requires a publisher, represented by the Publisher entity. A solution cannot use the Microsoft Corporation publisher but it can use the Default publisher for the organization or a new publisher
A publisher requires the following:
A customization prefix
A unique name
A friendly name
The following sample first defines a publisher and then checks to see whether the publisher already exists based on the unique name. If it already exists, the customization prefix may have been changed, so this sample seeks to capture the current customization prefix. The PublisherId is also captured so that the publisher record can be deleted. If the publisher is not found, a new publisher is created using the IOrganizationService. Create method
The following sample shows how to create an unmanaged solution using the Microsoft Dynamics 365 SDK Samples publisher created in Create a publisher.
A solution requires the following:
A Publisher
A Friendly Name
A Unique Name
A Version Number
The variable _crmSdkPublisherId is a GUID value representing the publisherid value.
This sample checks whether the Solution already exists in the organization based on the unique name. If the solution does not exist it is created. The SolutionId value is captured so the solution can be deleted.
To retrieve a specific solution you can use the solution’s UniqueName. Each organization will have a default solution with a constant GUID value: FD140AAF-4DF4-11DD-BD17-0019B9312238.
This sample shows how to retrieve data for a solution with the unique name ”samplesolution”. A solution with this name is created in Create a solution.
This sample shows how to create a solution component that is associated with a specific solution. If you don’t associate the solution component to a specific solution when it is created it will only be added to the default solution and you will need to add it to a solution manually or by using the code included in the Add an existing solution component.
This code creates a new global option set and adds it to the solution with a unique name equal to _primarySolutionName.
This sample shows how to add an existing solution component to a solution.
The following code uses the AddSolutionComponentRequest to add the Account entity as a solution component to an unmanaged solution.
This sample shows how to remove a solution component from an unmanaged solution. The following code uses the RemoveSolutionComponentRequest to remove an entity solution component from an unmanaged solution. The solution.UniqueName references the Solution created in the Create a solution.
This sample shows how to export an unmanaged solution or package a managed solution. The code uses ExportSolutionRequest to export a compressed file representing an unmanaged solution. The option to create a managed solution is set using the Managed property. This sample saves a file named samplesolution.zip to the c:\temp\ folder.
This sample shows how to install or upgrade a solution using the ImportSolutionRequest message.
You can use the ImportJob entity to capture data about the success of the import.
The following sample shows how to import a solution without tracking the success.
When you specify an ImportJobId for the ImportSolutionRequest, you can use that value to query the ImportJob entity about the status of the import.
The ImportJobId can also be used to download an import log file using the RetrieveFormattedImportJobResultsRequest message.
The following sample shows how to retrieve the import job record and the content of the ImportJob.Data attribute.
The contents of the Data property is a string representing an XML file. The following is a sample captured using the code in this sample. This managed solution contained a single global option set called sample_tempsampleglobaloptionsetname.
<importexportxml start="634224017519682730" stop="634224017609764033" progress="80" processed="true"> <solutionManifests> <solutionManifest languagecode="1033" id="samplesolutionforImport" LocalizedName="Sample Solution for Import" processed="true"> <UniqueName>samplesolutionforImport</UniqueName> <LocalizedNames> <LocalizedName description="Sample Solution for Import" languagecode="1033" /> </LocalizedNames> <Descriptions> <Description description="This solution was created by the WorkWithSolutions sample code in the Microsoft CRM SDK samples." languagecode="1033" /> </Descriptions> <Version>1.0</Version> <Managed>1</Managed> <Publisher> <UniqueName>sdksamples</UniqueName> <LocalizedNames> <LocalizedName description="Microsoft CRM SDK Samples" languagecode="1033" /> </LocalizedNames> <Descriptions> <Description description="This publisher was created with samples from the Microsoft CRM SDK" languagecode="1033" /> </Descriptions> <EMailAddress>someone@microsoft.com</EMailAddress> <SupportingWebsiteUrl>http://msdn.microsoft.com/en-us/dynamics/crm/default.aspx</SupportingWebsiteUrl> <Addresses> <Address> <City /> <Country /> <Line1 /> <Line2 /> <PostalCode /> <StateOrProvince /> <Telephone1 /> </Address> </Addresses> </Publisher> <results /> <result result="success" errorcode="0" errortext="" datetime="20:49:12.08" datetimeticks="634224269520845122" /> </solutionManifest> </solutionManifests> <upgradeSolutionPackageInformation> <upgradeRequired>0</upgradeRequired> <upgradeValid>1</upgradeValid> <fileVersion>5.0.9669.0</fileVersion> <currentVersion>5.0.9669.0</currentVersion> <fileSku>OnPremise</fileSku> <currentSku>OnPremise</currentSku> </upgradeSolutionPackageInformation> <entities /> <nodes /> <settings /> <dashboards /> <securityroles /> <workflows /> <templates /> <optionSets> <optionSet id="sample_tempsampleglobaloptionsetname" LocalizedName="Example Option Set" Description="" processed="true"> <result result="success" errorcode="0" errortext="" datetime="20:49:16.10" datetimeticks="634224269561025400" /> </optionSet> </optionSets> <ConnectionRoles /> <SolutionPluginAssemblies /> <SdkMessageProcessingSteps /> <ServiceEndpoints /> <webResources /> <reports /> <FieldSecurityProfiles /> <languages> <language> <result result="success" errorcode="0" errortext="" datetime="20:49:12.00" datetimeticks="634224269520092986" /> </language> </languages> <entitySubhandlers /> <publishes> <publish processed="false" /> </publishes> <rootComponents> <rootComponent processed="true"> <result result="success" errorcode="0" errortext="" datetime="20:49:20.83" datetimeticks="634224269608387238" /> </rootComponent> </rootComponents> <dependencies> <dependency processed="true"> <result result="success" errorcode="0" errortext="" datetime="20:49:20.97" datetimeticks="634224269609715208" /> </dependency> </dependencies> </importexportxml>
This sample shows how to delete a solution.The following sample shows how to retrieve a solution using the solution uniquename and then extract the solutionid from the results. Use the solutionid with the IOrganizationService. Delete method.
This sample shows how to create a report showing the dependencies between solution components.
This code will:
Retrieve all the components for a solution.
Retrieve all the dependencies for each component.
For each dependency found display a report describing the dependency.
The DependencyReport method is in the following code sample.
The DependencyReport method provides a friendlier message based on information found within the dependency.
Note |
|---|
In this sample the method is only partially implemented. It can display messages only for attribute and option set solution components. |
Use the RetrieveDependenciesForDeleteRequest message to identify any other solution components which would prevent a given solution component from being deleted. The following code sample looks for any attributes using a known global optionset. Any attribute using the global optionset would prevent the global optionset from being deleted.
Package and distribute extensions using solutions
Introduction to solutions
Plan for solution development
Dependency tracking for solution components
Create, export, or import an unmanaged solution
Create, install, and update a managed solution
Uninstall or delete a solution
Solution entities
Sample: Work with solutions
Sample: Detect solution dependencies
Microsoft Dynamics 365
© 2016 Microsoft. All rights reserved. Copyright
