1 回答
TA贡献1825条经验 获得超4个赞
如果我误解了你,请纠正我:我找不到 sdk Microsoft.Azure.Compute.Fluent(截图如下):
所以我改用这个sdk Microsoft.Azure.Management.Fluent(官方文档也使用它)。并且可以在我身边获取ip,代码如下:
using Microsoft.Azure.Management.Compute.Fluent;
using Microsoft.Azure.Management.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent.Core;
using System;
using System.Threading.Tasks;
namespace myVMDotnetProject
{
class Program
{
static void Main(string[] args)
{
GetVMInfo();
Console.WriteLine("okok");
Console.ReadLine();
}
static async Task GetVMInfo()
{
var credentials = SdkContext.AzureCredentialsFactory.FromFile(Environment.GetEnvironmentVariable("AZURE_AUTH_LOCATION", EnvironmentVariableTarget.User));
var azure = Azure
.Configure()
.WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
.Authenticate(credentials)
.WithDefaultSubscription();
IVirtualMachines _client = azure.VirtualMachines;
var list = await _client.ListAsync();
foreach (var instance in list)
{
var name = instance.Name;
var ip = instance.GetPrimaryPublicIPAddress().IPAddress;
Console.WriteLine("name: " + name + ", ip: " + ip);
}
}
}
}
测试结果如下:
- 1 回答
- 0 关注
- 111 浏览
添加回答
举报