A Publisher in Dynamics is the entity by which your solutions are deployed to Dynamics CRM.
No publisher means no solution being deployed.
In any Dynamics install, there is always a Default Publisher which you can use across your solutions (if you like) but exists as the publisher for customizations made to the base system.
Creating a publisher can be accomplished by simply going to Settings >> Customizations >> Publishers and creating your own publisher.
But that’s pretty boring, so we’re going to create one using code.
Creating your Publisher
Once you initialized a connection to Dynamics, put together a little console app and use the following code to create your own Publisher that can be used for deploying your own solutions.
Entity crmPublisher = new Entity("publisher");
crmPublisher["uniquename"] = "ForgottenCoder";
crmPublisher["friendlyname"] = "Forgotten Coder";
crmPublisher["supportingwebsiteurl"] = "www.forgottencoder.com";
crmPublisher["customizationprefix"] = "fgc";
crmPublisher["emailaddress"] = "email@example.com";
crmPublisher["description"] = "This publisher is used to create all customizations by Forgotten Coder.";
crmPublisher["customizationoptionvalueprefix"] = Convert.ToInt32("59999");
PublisherId = CrmService.Create(crmPublisher);
(Where CrmService is the IOrganizationService reference to my connection object.)
Run your code and you should have a newly created Publisher in Dynamics.
Some Publisher Specifics
Some important to pieces to understand with publishers (as they pertain to your solutions), the prefix is very important as all objects created within your solution will be prefixed with this prefix. Also, the Option Value Prefix indicates what number your option set will start from.
It’s important to note that Publishers and Solutions are not 1-to-1, you can have one publisher deploy many solutions but a solution can only have one publisher.
Searching for your Publisher
If you want to get fancy, you can do a lookup on startup of your application to see if your publisher exists and if so, go grab it’s PublisherId (you’re going to need it for your solution deployment) and store it in memory before deploying your solution.
QueryExpression pubQuery = new QueryExpression
EntityName = "publisher",
ColumnSet = new ColumnSet("publisherid"),
Criteria = new FilterExpression()
pubQuery.Criteria.AddCondition("uniquename", ConditionOperator.Equal, "ForgottenCoder");
EntityCollection results = CrmService.RetrieveMultiple(pubQuery);
Note: The above code snippet was modified from the Microsoft sample “Solutions” project shipped with the Dynamics SDK.