SDK for .NET Cloud Shell Quick Start

This topic explains how to quickly get started with the Oracle Cloud Infrastructure SDK for .NET using Cloud Shell.

This topic explains how to quickly get started with the Oracle Cloud Infrastructure SDK for .NET using Cloud Shell.

  1. Login to the Console.
  2. Click the Cloud Shell icon in the Console header. Note that Cloud Shell will execute commands against the region selected in the Console's Region selection menu when Cloud Shell was started.
  3. Create a working directory and move to it:
    mkdir DotnetDemo && cd DotnetDemo 
  4. Create a new .NET console application project:
    dotnet new console
  5. Add the OCI.DotNetSDK.Objectstorage package to your project.
    dotnet add package OCI.DotNetSDK.Objectstorage --source /usr/lib/dotnet/NuPkgs/

    Optionally, you can include the --source parameter, which will fall back to retrieving the package from the pre-installed location (/usr/lib/dotnet/NuPkgs/) if it cannot be downloaded from nuget.org.

    Note

    To bypass nuget.org and force usage of the pre-installed .NET SDK, you can use the nuget.config provided in step 2a of the instructions here.
  6. Add the following code to the Program.cs file:
    using System;
    using System.Collections.Generic;
    using System.Threading.Tasks;
    using Oci.ObjectstorageService;
    using Oci.ObjectstorageService.Requests;
    using Oci.ObjectstorageService.Responses;
    using Oci.Common.Auth;
     
    namespace DotnetDemo
    {
        public class Program
        {
            static void Main(string[] args)
            {
                var provider = new ConfigFileAuthenticationDetailsProvider("DEFAULT");
                var compartmentId = Environment.GetEnvironmentVariable("OCI_TENANCY");
                var objectStorageClient = new ObjectStorageClient(provider);
     
                Task<GetNamespaceResponse> getNamespaceResponse = objectStorageClient.GetNamespace(new GetNamespaceRequest());
                Console.WriteLine(getNamespaceResponse.Result.Value);
            }
        }
    }
  7. Run the example:
    dotnet run