Getting started with .Net (C#) SDK

2 minute read

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 Feature Management account. See Signup Page to create an account.

  2. Get your environment key.

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

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

Add the CloudBees Feature Management .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 RoxString titleColors = new RoxString("White", new String[] {"White", "Blue", "Green"});
    public RoxInt titleSize = new RoxInt(12, new String[] {12, 14, 18});
    public RoxDouble specialNumbers = new RoxDouble(3.14, new String[] { 2.71, 0.577 });
  }

    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());

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

            // int flag example
            Console.WriteLine("titleSize value is " + flags.titleSize.GetValue());

            // double flag example
            Console.WriteLine("speicalNumber value is " + flags.speicalNumber.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 Feature Management dashboard after running the application.