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.
- Login to the Console.
- 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.
- Create a working directory and move to
it:
mkdir DotnetDemo && cd DotnetDemo
-
Create a new .NET console application project:
dotnet new console
-
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 thenuget.config
provided in step 2a of the instructions here. -
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); } } }
-
Run the example:
dotnet run