集成Microsoft Dynamics 2011后,如何重新生成CrmEntities.cs文件?
Hey there, since you're new to CRM, let's break down exactly how to regenerate that CrmEntities.cs file to get those missing Account fields included. The key tool here is CrmSvcUtil.exe—Microsoft's official utility for generating strongly-typed entity classes from your CRM instance's metadata.
Step 1: Locate CrmSvcUtil.exe
First, find the tool in your Dynamics CRM 2011 SDK installation. It lives in the Bin folder (usually something like C:\CRM2011SDK\Bin\CrmSvcUtil.exe). If you don't have the SDK yet, grab the version matching your CRM server—make sure it's specifically for 2011, since newer SDK versions won't work correctly.
Step 2: Build Your Command Line
Open Command Prompt (CMD) and navigate to the folder where CrmSvcUtil.exe is stored. Then run a command formatted like this (replace the placeholders with your actual CRM details):
CrmSvcUtil.exe /url:http://your-crm-server/XRMServices/2011/Organization.svc /out:C:\YourProject\CrmEntities.cs /username:your-domain-username /password:your-password /domain:your-active-directory-domain /namespace:Your.Existing.Namespace /serviceContextName:CrmServiceContext
Let's break down the critical parameters so you don't mix anything up:
/url: The URL to your CRM organization's service endpoint—this is usually in the format above, but double-check with your CRM admin if you're unsure./out: The full path and filename where you want the newCrmEntities.cssaved. Point it directly to your project's folder if you want to overwrite the old file (just make a backup first!)./username//password//domain: Your AD credentials that have access to the CRM instance (needs at least read access to CRM metadata)./namespace: Use the exact same namespace as your originalCrmEntities.cs—this avoids breaking existing code references./serviceContextName: The name of the generated service context class; stick withCrmServiceContextunless your original file used something different.
Step 3: Run the Command
Hit enter, and the tool will connect to your CRM server, pull all entity and field metadata, and generate the updated CrmEntities.cs file. You'll see output in the CMD window showing progress—wait for it to finish without errors.
Step 4: Update Your Project
Replace the old CrmEntities.cs in your project with the newly generated one, then clean and rebuild your solution. Now when you query Accounts, those missing fields should be included in the returned data.
Quick Tips
- If your CRM uses Internet-Facing Deployment (IFD) instead of AD, add
/authenticationType:IFDto the command and use your IFD credentials. - Always back up the original
CrmEntities.csbefore overwriting it—just in case something goes wrong. - Make sure the account you're using has permission to access CRM metadata (system admin or a custom role with "Read Metadata" privileges will work).
内容的提问来源于stack exchange,提问作者John Travander

