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.
- Sign in to the Console.
- Click the Cloud Shell icon in the Console header. Note that Cloud Shell runs 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 the project.dotnet add package OCI.DotNetSDK.Objectstorage --source /usr/lib/dotnet/NuPkgs/
Optionally, you can include the
--source
parameter, which falls back to retrieving the package from the pre-installed location (/usr/lib/dotnet/NuPkgs/
) if it can't 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