The following code example will show you how to add solution components to an unmanaged solution specified in the SolutionUniqueName property using the AddSolutionComponentRequest Class. Adjust the ComponentType and ComponentId values depending on the type of component that you want to add to the solution.

//Retrieve a component (The contact entity is retrieved for this example).

var retrieveRequest = new RetrieveEntityRequest()
{
    LogicalName = Contact.EntityLogicalName
};

var retrieveResponse = (RetrieveEntityResponse)service.Execute(retrieveRequest);

//Add component to an unmanaged solution.

var addSolutionComponentRequest = new AddSolutionComponentRequest()
{
    ComponentType = (int)componenttype.Entity,
    ComponentId = (Guid)retrieveResponse.EntityMetadata.MetadataId,
    SolutionUniqueName = solution.UniqueName
};

service.Execute(addSolutionComponentRequest);

Dynamics 365 stores components of a CRM solution inside an entity called Solution Component. The componenttype field provides information on the object type code of these components. A complete list of these values can be found in the table below.

Value Label
1 Entity
2 Attribute
3 Relationship
4 Attribute Picklist Value
5 Attribute Lookup Value
6 View Attribute
7 Localized Label
8 Relationship Extra Condition
9 Option Set
10 Entity Relationship
11 Entity Relationship Role
12 Entity Relationship Relationships
13 Managed Property
14 Entity Key
16 Privilege
17 PrivilegeObjectTypeCode
20 Role
21 Role Privilege
22 Display String
23 Display String Map
24 Form
25 Organization
26 Saved Query
29 Workflow
31 Report
32 Report Entity
33 Report Category
34 Report Visibility
35 Attachment
36 Email Template
37 Contract Template
38 KB Article Template
39 Mail Merge Template
44 Duplicate Rule
45 Duplicate Rule Condition
46 Entity Map
47 Attribute Map
48 Ribbon Command
49 Ribbon Context Group
50 Ribbon Customization
52 Ribbon Rule
53 Ribbon Tab To Command Map
55 Ribbon Diff
59 Saved Query Visualization
60 System Form
61 Web Resource
62 Site Map
63 Connection Role
64 Complex Control
70 Field Security Profile
71 Field Permission
90 Plugin Type
91 Plugin Assembly
92 SDK Message Processing Step
93 SDK Message Processing Step Image
95 Service Endpoint
150 Routing Rule
151 Routing Rule Item
152 SLA
153 SLA Item
154 Convert Rule
155 Convert Rule Item
65 Hierarchy Rule
161 Mobile Offline Profile
162 Mobile Offline Profile Item
165 Similarity Rule
66 Custom Control
68 Custom Control Default Config
166 Data Source Mapping
201 SDKMessage
202 SDKMessageFilter
203 SdkMessagePair
204 SdkMessageRequest
205 SdkMessageRequestField
206 SdkMessageResponse
207 SdkMessageResponseField
210 WebWizard
18 Index
208 Import Map
300 Canvas App
371 Connector
372 Connector
380 Environment Variable Definition
381 Environment Variable Value
400 AI Project Type
401 AI Project
402 AI Configuration
430 Entity Analytics Configuration
431 Attribute Image Configuration
432 Entity Image Configuration

For solution components that derive from MetadataBase, the correct value of the ComponentId is the MetadataId property. For other solution components, use the property that is the unique identifier for the entity.