We could use the Azure fluent SDK Microsoft.Azure.Management.Fluent
and Microsoft.Azure.Management.ResourceManager.Fluent to do that. I also test it on my side. It works correctly on my side. About how to get the azure credential file, we could refer to Authentication in Azure Management Libraries for .NET
I used an authentication file.
subscription=########-####-####-####-############
client=########-####-####-####-############
tenant=########-####-####-####-############
key=XXXXXXXXXXXXXXXX
managementURI=https://management.core.windows.net/
baseURL=https://management.azure.com/
authURL=https://login.windows.net/
graphURL=https://graph.windows.net/
Demo code.
using Microsoft.Azure.Management.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent.Core;
using Microsoft.Azure.Management.ServiceBus.Fluent;
namespace CreateServiceBus
{
class Program
{
static void Main(string[] args)
{
var credentials = SdkContext.AzureCredentialsFactory.FromFile(@"C:TomazureCredential.txt");
var azure = Azure
.Configure()
.WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
.Authenticate(credentials)
.WithDefaultSubscription();
var sbNameSpace = "service bus name space";
var resoureGroup = "resourcegroup";
var serviceBusNamespace = azure.ServiceBusNamespaces
.Define(sbNameSpace)
.WithRegion(Region.USEast)
.WithNewResourceGroup(resoureGroup)
.WithSku(NamespaceSku.Basic)
.Create();
}
}
}
Packages.config
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Azure.Management.AppService.Fluent" version="1.0.0" targetFramework="net462" />
<package id="Microsoft.Azure.Management.Batch.Fluent" version="1.0.0" targetFramework="net462" />
<package id="Microsoft.Azure.Management.Cdn.Fluent" version="1.0.0" targetFramework="net462" />
<package id="Microsoft.Azure.Management.Compute.Fluent" version="1.0.0" targetFramework="net462" />
<package id="Microsoft.Azure.Management.Dns.Fluent" version="1.0.0" targetFramework="net462" />
<package id="Microsoft.Azure.Management.Fluent" version="1.0.0" targetFramework="net462" />
<package id="Microsoft.Azure.Management.Graph.RBAC.Fluent" version="1.0.0" targetFramework="net462" />
<package id="Microsoft.Azure.Management.KeyVault.Fluent" version="1.0.0" targetFramework="net462" />
<package id="Microsoft.Azure.Management.Network.Fluent" version="1.0.0" targetFramework="net462" />
<package id="Microsoft.Azure.Management.Redis.Fluent" version="1.0.0" targetFramework="net462" />
<package id="Microsoft.Azure.Management.ResourceManager.Fluent" version="1.1.3" targetFramework="net462" />
<package id="Microsoft.Azure.Management.ServiceBus.Fluent" version="1.0.0" targetFramework="net462" />
<package id="Microsoft.Azure.Management.Sql.Fluent" version="1.0.0" targetFramework="net462" />
<package id="Microsoft.Azure.Management.Storage.Fluent" version="1.0.0" targetFramework="net462" />
<package id="Microsoft.Azure.Management.TrafficManager.Fluent" version="1.0.0" targetFramework="net462" />
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="2.28.3" targetFramework="net462" />
<package id="Microsoft.Rest.ClientRuntime" version="2.3.8" targetFramework="net462" />
<package id="Microsoft.Rest.ClientRuntime.Azure" version="3.3.8" targetFramework="net462" />
<package id="Microsoft.Rest.ClientRuntime.Azure.Authentication" version="2.3.0" targetFramework="net462" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net462" />
</packages>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…