您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

用于 .NET 的 Azure 虚拟机库Azure virtual machine libraries for .NET

概述Overview

运行 Linux 或 Windows 的按需可缩放计算资源。On-demand, scalable computing resources running Linux or Windows.

若要开始使用 Azure 虚拟机,请参阅使用 Azure 门户创建 Linux 虚拟机To get started with Azure virtual machines, see Create a Linux virtual machine with the Azure portal.

管理 APIManagement APIs

使用管理 API 通过代码在 Azure 中创建、配置和横向扩展 Windows 与 Linux 虚拟机。Create, configure, and scale out Windows and Linux virtual machines in Azure from your code with the management API.

直接从 Visual Studio 包管理器控制台或使用 .NET Core CLI 安装 NuGet 包Install the NuGet package directly from the Visual Studio Package Manager console or with the .NET Core CLI.

Visual Studio 包管理器Visual Studio Package Manager

Install-Package Microsoft.Azure.Management.Compute.Fluent

.NET Core CLI.NET Core CLI

dotnet add package Microsoft.Azure.Management.Compute.Fluent

代码示例Code Example

创建 Windows VM。Create a Windows VM.

/* Include these "using" directives...
using Microsoft.Azure.Management.Compute.Fluent;
using Microsoft.Azure.Management.Compute.Fluent.Models;
using Microsoft.Azure.Management.ResourceManager.Fluent.Core;
*/

IVirtualMachine windowsVM = azure.VirtualMachines.Define("MyVirtualMachine")
    .WithRegion(Region.USEast)
    .WithNewResourceGroup("MyResourceGroup")
    .WithNewPrimaryNetwork("10.0.0.0/28")
    .WithPrimaryPrivateIPAddressDynamic()
    .WithNewPrimaryPublicIPAddress("MyIPAddressLabel")
    .WithPopularWindowsImage(KnownWindowsVirtualMachineImage.WindowsServer2012R2Datacenter)
    .WithAdminUsername("UserName")
    .WithAdminPassword("Password")
    .WithSize(VirtualMachineSizeTypes.StandardD3V2)
    .Create();

示例Samples

查看虚拟机示例的完整列表View the complete list of virtual machine samples.