Setting Up Couchbase .NET SDK with Visual Studio 2019 or VSCode

    +
    Discover how to get up and running developing applications with the Couchbase .NET SDK 3.0+ using Visual Studio 2019 or Visual Studio Code.

    A simple .NET orientation intro for non-.NET folk who are evaluating the Couchbase .NET SDK.

    Is This Page for You?

    This page is to help evaluate the Couchbase .NET SDK, if .NET is not where you spend the majority of your working day. It is aimed at Software Architects, QE folk, managers, and anyone else who needs to run through using the .NET SDK without necessarily being comfortable with C# and the .NET environment. If this is not you, head back to the rest of the Couchbase .NET SDK documentation.

    Using an IDE (Visual Studio 2019 Community)

    • Download Visual Studio 2019 for Windows; note that the Community edition is free! https://visualstudio.microsoft.com/vs/

    • Click on the Visual Studio Installer and select the following work flows

      • .NET desktop development (required for demos)

      • ASP.NET and web development (optional)

    • Click Install and let the installation continue; we suggest leaving the defaults in place.

    • Once installation has been completed, you can create a new application by including a dependency on the .NET SDK via NuGet or by downloading an example application that already has the dependencies defined.

    • Details for installing Visual Studio on other operating systems can be found here:

    Using a Code Editor (Visual Studio Code)

    Visual Studio Code is a free code editor which runs on Windows, Linux and MacOS and can be downloaded here. Once downloaded, follow the installation details for the relevant platform:

    Adding C# Development Support

    VSCode is an editor, so in order to have support for various languages like C#, GO, Python, etc. you will need to install a 3rd party extension which supports development in said programming language. For .NET, we suggest using ms-dotnettools.csharp which allows for development in C#, the most commonly used .NET language.

    • Navigate to https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp

    • Click on Install at the top, left hand side.

    • Select Open Visual Studio Code which will install ms-dotnettools.csharp into the VSCode editor

    • Alternatively, install from VSCode directly:

      • Open VSCode

      • Select the Extensions button on the left hand side

      • Type ms-dotnettools.csharp into the Search Extensions Marketplace textbox and hit enter

      • Select and install the language extension into the editor.

    Installing SDK Core

    This doesn’t need to be done if you’re using Visual Studio 2019; however, it is required if you are using VSCode because it is not installed by default.

    Getting started developing with the SDK

    Using Visual Studio Community

    • Windows

    • MacOS

    Open Visual Studio from the start menu and click File⇒New⇒Project:

    • In the New Project dialogue, Installed⇒Visual C# from the top Menu

      • Select Console App (.NET Core)

      • Type CouchbaseExample in the Name textbox

      • Leave the Location textbox to its default

      • Leave the Solution Name to its default

      • Click Ok - a solution and project will be created

    • Add the NuGet dependency on CouchbaseNetClient to the project:

      • Right Click on the CouchbaseExample project in the Solution Explorer pane of Visual Studio

      • In the Context Menu select Manage NuGet Packages…

      • Click Browse in the NuGet Package Manager

      • Type CouchbaseNetClient into the search text box making sure Include Pre-Release checkbox is selected if you wish to see pre-GA releases

      • Select the version to install from the dropdown and click Install

    Open Visual Studio and click File⇒New⇒Solution:

    • In the New Project dialogue, Web and Console⇒App from the Menu on the Left:

      • Select Console Application and C# from the small dropdown (already selected by default)

      • Leave the Target Framework to its default

      • Type CouchbaseExample in the Project Name textbox

      • Leave the Solution Name to its default

      • Leave the Location textbox to its default

      • Click Ok - a solution and project will be created

    • Add the NuGet dependency on CouchbaseNetClient to the project:

      • Right Click on the CouchbaseExample project in the Solution Explorer pane of Visual Studio

      • In the Context Menu select Manage NuGet Packages…

      • Select Browse in the NuGet Package Manager

      • Type CouchbaseNetClient into the search text box making sure Include Pre-Release checkbox is selected if you wish to see pre-GA releases

      • Select the version to install from the dropdown and click Add Package

    Using VSCode

    If you are using VSCode it is often easier to use both the editor and the Command Line Interface (CLI):

    • Open a terminal and make a directory for your project: mkdir CouchbaseExample

    • Go into the directory: cd CouchbaseExample

    • Create the console project: dotnet new console

    • Install the CouchbaseNetClient package: dotnet add package CouchbaseNetClient

    • Run the application: dotnet run

    You should see a Hello World message printed in your terminal, which means the application has run successfully.

    Now you can launch VSCode and open the CouchbaseExample directory to start editing the Program.cs file.

    That’s it! You are now ready to start developing your Couchbase application.