Udostępnij za pośrednictwem


Start a managed code project in Visual Studio

 

Applies To: Dynamics 365 (online), Dynamics 365 (on-premises), Dynamics CRM 2016, Dynamics CRM Online

This topic shows you how to create a new project in Microsoft Visual Studio that’s properly configured to build a console application that uses the Microsoft Dynamics 365 SDK. Learn what required references must be added to your project when building an application that links to the Microsoft Dynamics 365 SDK assemblies.

Prerequisites

  • Microsoft Visual Studio installed on your development computer.

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

  • The Microsoft Dynamics 365 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.

Create a project

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

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.5.2.

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

    A new console app project dialog in Dynamics CRM

  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.5.2.

    Choose the target framework for the CRM project

Add all required references to your project

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

An alternate and easy method to add the required references to you project is to use the available NuGet SDK package. Using the NuGet package manager in Visual Studio, find and add the Microsoft.CrmSdk.CoreAssemblies package to your project. You can then skip the remaining instructions in this topic.

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 box, select the Browse button, and then navigate to the folder where you extracted the Microsoft Dynamics 365 SDK.

  3. In the Bin folder of the SDK download, select the Microsoft.Crm.Sdk.Proxy.dll and Microsoft.Xrm.Sdk.dll assemblies, and then click Add.

  4. Select OK.

There are other Microsoft Dynamics 365 SDK assembly references that you may need at some time depending on the nature of the project you’re building. However, for writing application code that accesses the organization web service, the previously mentioned references are all you need. More information: Assemblies included in the Microsoft Dynamics 365 SDK.

Add the required Identity references

  1. Turn the Windows featured named Windows Identity Foundation (WIF) on. To do this, navigate to Control Panel > Programs > Programs and Features. Select Turn Windows features on or off. Next, select (check) Windows Identity Foundation (WIF) 3.5 in the list.

    Alternately, you can download and install the Windows Identity Foundation (WIF) version 3.5 library, named WindowsIdentityFoundation-SDK-3.5.msi.

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

  3. In the search box, enter System.IdentityModel.

  4. Select System.IdentityModel in the search results list and click OK.

  5. Similar to what was done in steps 2 to 4, add a reference for Microsoft.IdentityModel.

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

Add the project references for the CRM project

Next Steps

Tip

Before you leave this topic, consider saving your project as a project template. You can then reuse 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

Microsoft Dynamics 365

© 2016 Microsoft. All rights reserved. Copyright