Start a managed code project in Visual Studio

 

Applies To: Dynamics CRM 2013

This topic shows you how to create a new project in Microsoft Visual Studio that is properly configured to build a console application that uses the Microsoft Dynamics CRM SDK. You will also install the required Windows Identity Foundation run-time that is used for authentication with the Microsoft Dynamics CRM web services.

Prerequisites

  • Microsoft Visual Studio installed on your development computer.

    Any edition including Express should work. For more information on what versions of Microsoft Visual Studio are supported, see Visual Studio and the .NET Framework.

  • The Microsoft Dynamics CRM SDK installed on your development computer.

    Download the Microsoft Dynamics CRM SDK package. Run the downloaded executable file to unpack the package to any folder on your development system.

Steps

  1. Create a project

  2. Install Windows Identity Foundation (WIF) 3.5

  3. Add all required references to your project

Create a project

The following procedure demonstrates how to create a console application project in the C# or VB language that uses the Microsoft .NET Framework 4. For more information on supported versions of the .NET framework, see Supported extensions for Microsoft Dynamics CRM 2013.

New project

  1. In Microsoft Visual Studio, select New Project.

  2. In the left navigation pane under Templates, select Visual C# or Visual Basic.

  3. Above the list of available templates, select .NET Framework 4.

  4. In the list of templates, select Console Application.

    Screenshot of new console app project dialog

  5. In the fields near the bottom of the form give the project a name and location, and then select OK.

  6. Under the Project menu, open the project’s properties form and verify the target framework is set to .NET Framework 4. Do not use .NET Framework 4 Client Profile.

    Choose the target framework for the project

Install Windows Identity Foundation (WIF) 3.5

Even if you are developing on a computer that is running Windows 8 or Windows Server 2012 you must install Windows Identity Foundation 3.5. This only needs to be done once for each development, staging, or production computer that your application will run on.

Enable WIF 3.5 on Windows 8 or Windows Server 2012

  1. Run a Command Prompt window or PowerShell window as administrator.

  2. Enter the following command to enable WIF 3.5.

    dism /online /enable-feature:windows-identity-foundation

Install WIF 3.5 on Windows 7 or Windows Server 2008

  1. Download Windows Identity Foundation 3.5 from the Microsoft Download Center.

  2. Install the downloaded file.

Add all required references to your project

The following procedures instruct you how to add all required references to your project. Consider this a base set of references that most managed code applications will need for calling web service methods.

Add the required system references

  1. In Solution Explorer, right click the project References node, select Add References, and then add the following references to your project.

    • System.Data.Linq

    • System.DirectoryServices.AccountManagement

    • System.Runtime.Serialization

    • System.Security

    • System.ServiceModel

Add the required SDK assembly references

  1. In Solution Explorer, right click the project References node, and then select Add References.

  2. In the Reference Manager dialog, select the Browse button, and then navigate to the folder where you extracted the Microsoft Dynamics CRM SDK.

  3. In the Bin folder of the SDK download, hold down the CTRL key while selecting the Microsoft.Crm.Sdk.Proxy.dll and Microsoft.Xrm.Sdk.dll assemblies, and then click Add.

  4. Select OK in the Reference Manager dialog.

There are other Microsoft Dynamics CRM SDK assembly references that you may need at some time depending on the nature of the project you are building. However, for writing application code that accesses the organization web service, the above references are all you need. For more information about the assemblies provided in the Microsoft Dynamics CRM SDK, see Assemblies included in the Microsoft Dynamics CRM SDK 2013.

Add the required Identity reference

  1. In Solution Explorer, right click the project References node, and then select Add References.

  2. In the search box of the dialog, enter Microsoft.IdentityModel.

  3. Select Microsoft.IdentityModel.dll in the search results list and click OK. If the DLL is not found, you can browse to its location in the file system at Program Files\Reference Assemblies\Microsoft\Windows Identity Foundation\v3.5.

The following diagram shows all the required references added to a project.

Add the project references for the project

Next Steps

Tip

Before you leave this topic, consider saving your project as a project template. You can then re-use that template for future learning projects and save yourself some time and effort in setting up new projects. To do this, while your project is open in Microsoft Visual Studio, in the File menu select Export template. Follow the wizard instructions to create the template.

See Also

Getting started with managed code application development
How to build and run the Dynamics CRM SDK samples on Windows Server 2012 and Windows 8