Quickstart : Azure Management Libraries for .NET

Here are basic steps :

API Reference

  1. Credentials
  2. Azure SDK for .NET doesn’t support interactive login. So you need to create application within your Azure Active Directory.

    • Log into Azure Portal
    • Navigate to Azure Active Directory
    • Click on App Registration
    • Click on New registration plus button
    • Enter a name and click on Register button
    • Once the app is created, click on it
    • Click on Certificates & Secrets as shown below
    • Create a new client secret. Save the secret right away, portal will not show it again
  3. Permissions
  4. We need to allow above created app to create resources in our Azure Subscription

    • Navigate to your Subscription in Azure Portal
    • Click on Access Control
    • Click on Add under Add a Role assignment
    • Set the Role to Owner
    • Select the app we created in the above step
    • Click SAVE as shown below

  5. Code
  6. Add these two NuGet Packages

    • Microsoft.Azure.Management.Fluent
    • Microsoft.Azure.Management.AppService.Fluent
    using System;
    using Microsoft.Azure.Management.ResourceManager.Fluent.Core;
    using Microsoft.Azure.Management.AppService.Fluent;
    using Microsoft.Azure.Management.Fluent;
    using Microsoft.Azure.Management.ResourceManager.Fluent.Authentication;
    using Microsoft.Azure.Management.ResourceManager.Fluent;
    using Microsoft.Azure.Management.AppService.Fluent.Models;
    
    namespace AzureFluent
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("Hello World!");
    
                string clientId = "";
                string clientSecret = "";
                string tenantId = "";
    
                string resourceGroupName = "MyFluent";
                string websiteName = "MyFluent";
                string customDomain = "wabac.in";
    
                var credentials = new AzureCredentialsFactory().FromServicePrincipal(clientId, clientSecret, tenantId, AzureEnvironment.AzureGlobalCloud);
    
                var azure = Azure
                            .Configure()
                            .Authenticate(credentials)
                            .WithDefaultSubscription();
    
                IWebApp app1 = azure.WebApps
                                .Define(websiteName)
                                .WithRegion(Region.JapanWest)
                                .WithNewResourceGroup(resourceGroupName)
                                .WithNewWindowsPlan(PricingTier.StandardS1)
                                .Create();
    
                //no option to upload private cert
                //WebAppsOperationsExtensions.CreateOrUpdatePublicCertificateAsync
    
                var hostNameBinding = new HostNameBindingInner
                {
                    SslState = SslState.SniEnabled,
                    Thumbprint = "F4FE3A86591F14B4397276B0D56C5D7FDD434877"
                };
    
                IWebAppsOperations ops = azure.WebApps.Inner;
    
                var t = ops.CreateOrUpdateHostNameBindingAsync(resourceGroupName, websiteName, customDomain, hostNameBinding);
    
                t.Wait();
            }
        }
    }
    
    

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Create a free website or blog at WordPress.com.

Up ↑