Getting started with .Net (C#) SDK

This section describes how to set up and install the .NET (C#) SDK and how to deploy a feature flag.

Step 1: Setting up

To setup .Net (C#) SDK, follow these steps:

  1. Create a CloudBees Rollout account. See Signup Page to create an account.

  2. Create an application in the CloudBees Rollout dashboard.

    • The first time you log into your account, click the Create New App button to create a new app.

      Create New App button

  3. Get your environment key.

    • Get the key from App Settings > Environment > Key.

Step 2: Installing the .Net (C#) SDK

Add the CloudBees Rollout .Net (C#) library to your application by adding the library rox-server or use the command line:

Package Manager CLI
# Add the SDK to your project
$ Install-Package rox-server
# Add the SDK to your project
$ dotnet add package rox-server

Add the following lines of code to your application:

using Io.Rollout.Rox.Server;
using Io.Rollout.Rox.Core.Entities;
using Io.Rollout.Rox.Server.Flags;
using System;
using System.Threading.Tasks;


namespace dotnet
{
  // Create a Roxflag in the Flag continer class
  public class Flags : IRoxContainer {
    public RoxFlag enableTutorial = new RoxFlag(false);
    public RoxVariant titleColors = new RoxVariant("White", new String[] {"White", "Blue", "Green"});
  }

    class Program
    {
        static async Task Main(string[] args)
        {
            Flags flags = new Flags();

            // Register the flag container
            Rox.Register("", flags);

            var options = new RoxOptions(new RoxOptions.RoxOptionsBuilder {});

            // Set the environment key
            await Rox.Setup("<ROLLOUT-ENV-KEY>", options);

            // Boolean flag example
            Console.WriteLine("enableTutorial " + flags.enableTutorial.IsEnabled());

            // Multivariate flag example
            Console.WriteLine("titleColors value is " + flags.titleColors.GetValue());
        }
    }
}

Container class registration and environment key setup

  • You cannot call Rox.setup() twice in the same runtime.

Run your application

Running the application

The flag name is automatically added to the CloudBees Rollout dashboard after running the application.

Step 3 - Deploying a feature flag

Finding your flags in the CloudBees Rollout dashboard

After creating feature flags and running your feature code, you can find your flags in the CloudBees Rollout dashboard.

To find your flags in the dashboard:

  1. Find your application in the CloudBees Rollout dashboard. To switch between apps, click on the app name in the top-left corner of the screen and select the app you want from the pulldown.

  2. Click on Flags on the left side of the navigation panel.

  3. Confirm that your flag is listed in the flag view.

Configuring deployment rules

  1. Go to the CloudBees Rollout dashboard.

  2. Click on Experiments on the left panel.

  3. Click the Create Experiment button to create a new experiment.

  4. In the New Experiment window:

    • Find the Flag name from the menu, choose it.

    • Click the Set Audience button to continue. The Experiment Details view appears.

  5. Select either True, False, Split or Scheduled. Split allows you to select the percentage of the target group that you want to deploy. Scheduled allows you to schedule a deployment date.

    Audience

  6. Click Update Audience.

  • You cannot delete the default condition.

  • You can click the Reset link to go back to the state from before you started making changes. Reset only appears when you’ve made saved modifications.

See Audience for more detailed information.