To use Alibaba Cloud C# SDK, you must have an Alibaba Cloud account and an AccessKey.
The AccessKey is required when initializing the client. You can create an AccessKey in the Alibaba Cloud console. For more information, see Create an AccessKey.
Note: To increase the security of your account, we recommend that you use the AccessKey of the RAM user to access Alibaba Cloud services.
To use Alibaba Cloud C# SDK to access the APIs of a product, you must first activate the product on the Alibaba Cloud console if required.
The Alibaba Cloud C# SDK is requires .NET Framework 4.0 or later.
You must install the SDK core library for any SDK you use. For example, to call the ECS SDK, you must install both the ECS SDK and the SDK core library.
Install the Alibaba Cloud C# SDK using one of the following methods:
Add DLL reference
Download the DLL package from .NET SDK.
Right click your project in the Solution Explorer of Visual Studio and click Reference.
In the displayed menu, click Add Reference.
In the displayed dialog box, click Browse. Then select the downloaded DLL file and click Confirm.
Add project reference
Run the following command to clone the SDK source codes from GitHub.
git clone https://github.com/aliyun/aliyun-openapi-net-sdk.git
There are many folders prefixed with
aliyun-net-openapi-in the cloned directory. Each folder contains
\\*.csprojfile, which is the project file**. For example, there is an
aliyun-net-sdk-ecs.csprojfile under the
In Visual Studio, right click your solution.
Click Add > Existing Project.
In the displayed dialogue box, select the project file, for example,
aliyun-net-sdk-ecs.csproj, and click then Open.
Right click your project and click Reference > Add Reference.
In the displayed dialog box, click the Project tab, select the opened project and click Confirm.
When using the Alibaba Cloud C# SDK to access Alibaba Cloud services, you need an Alibaba Cloud account for authentication.
C# SDK supports the following authentication methods.
|AccessKey||Use the AccessKeyID/Secret to do the authentication|
|StsToken||Use the STS Token to do the authentication|
|RamRoleArn||Use the AssumeRole of the RAM account to do the authentication|
|EcsRamRole||Use the RAM role of an ECS instance to do the authentication|
|RsaKeyPair||Use the RSA key pair to do the authentication (supported only on Japan site)|
This document uses AccessKey as an example to illustrate how to set up credentials.
Note: To ensure the security of your account, we recommend using your RAM account instead of the primary account. The primary account has full access to all of your cloud services, while the RAM account has limited access granted by the primary account to the cloud services.
Firstly, create an AccessKey as described in Create an AccessKey, and then set up your credentials when initializing
AcsClient as follows:
Note: Do not disclose any code containing your AccessKey (do not commit the code to public GitHub projects). Otherwise, your Alibaba Cloud account may be compromised.
IClientProfile clientProfile = DefaultProfile.GetProfile(
The following code example shows the three main steps to use the Alibaba Cloud C# SDK.
Create a client.
DefaultAcsClient client = new DefaultAcsClient(clientProfile);
Create a request.
DescribeInstancesRequest request = new DescribeInstancesRequest();
request.PageSize = 10;
The naming convention for the request is
apiNameis the action to perform, for example,
If the API names are duplicate, the workspace name is used to differentiate the request.
Send a request and handle the response.
DescribeInstancesResponse response = client.GetAcsResponse(request);
All the returned attributes are deserialized into the response. You can directly call
response.xxxto obtain the response attributes.