- In Visual Studio, create a new “Class Library” project as shown in the following screen shot
- Delete the class file “class1.cs” created by the Visual Studio.
- Add the references to following files to the project. These files can be find in SDK\Bin folder of CRM SDK. You can add a reference by right-clicking the name of your project and then selecting Add Reference.
- CrmSvcUtil.exe
- Microsoft.Crm.Sdk.Proxy.dll (Only needed for the on-premise and IFD installation)
- Microsoft.Xrm.Sdk.dll
- Click on “Show All Files” in solution explorer as shown in the following screen shot.
- The solution explorer will look like the following screen shot.
- Click on “bin” folder highlighted in yellow in the above screen shot. It will open open up an another folder “debug”.Click on the debug folder.Now the solution explorer will look like the following screen shot.
- Now we need to add CrmSvcUtil.exe.config to the debug folder. There are following two ways to achieve this.
- Add the file to debug folder by using window explorer outside the visual studio.
- or Right Click on the bin folder in the solution explorer and select “Include in project”. Now Select the debug folder and add an application configuration file by selecting “Project” menu----“Add New Item”---“Application Configuration File”.
- CrmSvcUtil.exe.config will contain “CrmSvcUtil.exe parameters”. The solution explorer will look like a following screen shot.
- Here is a list of all the parameters we can use with CrmSvcUtil.
- Add the following keys to CrmSvcUtil.exe.config file.
<?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="url" value="https://cdc.crm5.dynamics.com/XRMServices/2011/Organization.svc"/> <add key="o" value="CrmProxy.cs"/> <add key="u" value="username@live.com"/> <add key="p" value="password"/> <add key="servicecontextname" value="XrmContext"/> </appSettings> </configuration>
- Now the interesting part, right click on project node and press properties.
- It will pop up a following dialog box. Click on the “Build Events” tab.
- Type "$(TargetDir)CrmSvcUtil.exe" in “Post-build event command line” and choose “On Successful build” on “Run the post-build event” as shown in the above screen shot.
- Now Build the solution.
- You can check the “Output Window” of Visual Studio for the result. If everything goes smoothly, it will create “CrmProxy.cs” file in debug folder.
- Click on “Refresh” button in solution explorer and you can see the file in the debug directory.
- Check the CrmProxy.cs, it will have all the crm entities classes and "XrmContext".
Tips
- You can add, remove and edit keys in CrmSvcUtil.exe.config to pass parameters to code generator tool.
- Try accessing the CRM through the browser before debugging, if you are working with CRM Online.
- You can add this project to any of your crm solution. Change the <add key="o" value="CrmProxy.cs"/> entry in the config file to generate the output file in the desired folder. for e.g <add key="o" value="C:\Users\amreek\Desktop\CrmProxy.cs"/>
Note
-
I have chosen to run the CrmSvcUtil.exe in Post-build event. I will explain the reason in my next blog.
You need to run this only if there are changes in the schema , not every build !!
ReplyDeleteThanks for the feed back budddy. I m just suggesting an approach. You can use it the way you would like to use it.
DeleteI am going to add this project to all of crm projects and run this for every project just by changing the values in the config file.
Mscrm Shop: How To Use Crmsvcutil (Improved Version) In Visual Studio Part 2 >>>>> Download Now
Delete>>>>> Download Full
Mscrm Shop: How To Use Crmsvcutil (Improved Version) In Visual Studio Part 2 >>>>> Download LINK
>>>>> Download Now
Mscrm Shop: How To Use Crmsvcutil (Improved Version) In Visual Studio Part 2 >>>>> Download Full
>>>>> Download LINK p4
This worked like a charm thanks! a had a little problem with the post-build command line, because my TargetDir had spaces in it. I ended up putting the director location in quotes as someone suggest.. like "c:\vs 2010\projects\bin\Debug\CrmSvcUtil.exe". The build worked after that.
ReplyDeleteThanks for the info.
Deletecan you please send the complete "post-build event command line" please ?
ReplyDeleteI have tried putting in quotes but didnt work foe me.
I have follow the above steps , but step 6 does not show the files in bin - debug folder. whay is that?
ReplyDeleteI encountered the same problem and I got around it by adding CrmSvcUtil.exe and Microsoft.Xrm.Sdk.dll to the debug folder using the Add -> Existing Item functionality
DeleteIf you have added the references in step 3. these files should be there.
ReplyDeleteRegards..
I have reopen the project again I can see the files now, in step 10 URL username and password do I need to change these?
ReplyDeleteYes, you should use your CRM credentials.
DeleteRegards
I'm getting an "Exited with Code 1" and it spits out the standard help text.
ReplyDeleteIt seems that it's not paying attention to the Config file.
I've tried both CrmSvcUtil.config and App.config.
I'm running VS 2012 and on premise CRM 2011.
Any thoughts?
Hi I am so grateful I found your webpage, I really
ReplyDeletefound you by mistake, while I was looking on Aol for something else, Nonetheless I am here now and would
just like to say many thanks for a remarkable post and a all
round exciting blog (I also love the theme/design), I don't have time to look over it all at the moment but I have saved it and also included your RSS feeds, so when I have time I will be back to read much more, Please do keep up the excellent job.
Also visit my page Chaussure De Foot
You ROCK!
ReplyDeleteI can't tell you how much I appreciate this -- will save me just buckets of time!
Great post!
Thanks. I am glad it helped.
DeleteI have a solution with 3 distinct projects, each with a different namespace. I want to generate 3 different files, each with different parameters. is this possible with this method?
ReplyDeleteIn case it wasn't clear, I want to make all 3 servicecontext files with 1 project in 1 build.
Deletee cigarette, e cigarettes, vapor cigarette, ecig forum, electronic cigarette, ecigs
ReplyDeleteError 1 The command "c:\users\username\documents\visual studio 2012\Projects\OnPremTest\OnPremTest\bin\Debug\Crm.exe" exited with code 9009. Please let me know the solution
ReplyDeleteYour solution just saved me, i have been on these for over a month, i was using the command prompt but it didn't work. Thanks a lot
ReplyDeleteThere may be noticeably a bundle to find out about this. I assume you made sure nice factors in features also. online casino real money
ReplyDelete