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 365 | Integration, Dataverse...
Answered

Need to change publisher on CRM Solution using C# code

(0) ShareShare
ReportReport
Posted on by 325

Hi All,

Does anyone know how we can modify settings of a CRM solution using C# code? Like we need to change publisher using C# coding in a console application or some other application.

We need to remove the existing publisher and set another publisher programmatically using C# code.


Thanks

I have the same question (0)
  • Verified answer
    Thangamani Profile Picture
    507 on at

    Hi Muhammad,

        As per CRM SDK we will be able to create,update and retrieve the publishers of the solution.Below is the code for to create the publisher via programmatically.Use the code to create a new publisher and update the same publisher for a solution just using the update request instead of create.WHile updating you need to provide the ID of the publisher which is created.

    /Define a new publisher

                       Publisher _crmSdkPublisher = new Publisher

                       {

                           UniqueName = "sdksamples",

                           FriendlyName = "Microsoft CRM SDK Samples",

                           SupportingWebsiteUrl = "msdn.microsoft.com/.../default.aspx",

                           CustomizationPrefix = "sample",

                           EMailAddress = "someone@microsoft.com",

                           Description = "This publisher was created with samples from the Microsoft Dynamics CRM SDK"

                       };

                       //Does publisher already exist?

                       QueryExpression querySDKSamplePublisher = new QueryExpression

                       {

                           EntityName = Publisher.EntityLogicalName,

                           ColumnSet = new ColumnSet("publisherid", "customizationprefix"),

                           Criteria = new FilterExpression()

                       };

                       querySDKSamplePublisher.Criteria.AddCondition("uniquename", ConditionOperator.Equal, _crmSdkPublisher.UniqueName);

                       EntityCollection querySDKSamplePublisherResults = _serviceProxy.RetrieveMultiple(querySDKSamplePublisher);

                       Publisher SDKSamplePublisherResults = null;

                       //If it already exists, use it

                       if (querySDKSamplePublisherResults.Entities.Count > 0)

                       {

                           SDKSamplePublisherResults = (Publisher)querySDKSamplePublisherResults.Entities[0];

                           _crmSdkPublisherId = (Guid)SDKSamplePublisherResults.PublisherId;

                           _customizationPrefix = SDKSamplePublisherResults.CustomizationPrefix;

                       }

                       //If it doesn't exist, create it

                       if (SDKSamplePublisherResults == null)

                       {

                           _crmSdkPublisherId = _serviceProxy.Create(_crmSdkPublisher);

                           Console.WriteLine(String.Format("Created publisher: {0}.", _crmSdkPublisher.FriendlyName));

                           _customizationPrefix = _crmSdkPublisher.CustomizationPrefix;

                       }

    Hope this helps.

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 365 | Integration, Dataverse, and general topics

#1
Siv Sagar Profile Picture

Siv Sagar 93 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 74

#3
Martin Dráb Profile Picture

Martin Dráb 64 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans