How to deploy an application to an App Service using the new Azure Management libraries?

Alexandre 351 Reputation points
2022-08-13T14:16:14.027+00:00

I have packaged a .NET application (in a zip file) that I want to deploy to an existing App Service. For that, I want to use the new Azure Management libraries in .NET (like this one).
I have read this quick start for the new Management libraries which is exactly what I want to use, however, the documentation does not indicate how to retrieve an existing App Service and how to deploy a package on it.

I have seen this sample which is similar to what I want to do but that uses the "old SDK". I am interested in using the new Azure SDKs because it's what I am already using on my application, with Azure Identity...

I need to do this deployment from C# code so I don't want to use Azure CLI, PowerShell, or do that from a CI/CD pipeline. I would prefer using the Azure Management Librarie than making an HTTP call to an Azure API to do a Zip deploy or something like that.

I would have the same question for deploying a package to a Function App using Azure Management libraries. I expect the answer to be similar to deploying to an App Service.

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,647 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Ryan Hill 27,111 Reputation points Microsoft Employee
    2022-08-15T17:05:08.087+00:00

    I realize @Alexandre , that the quick start guide doesn't mention app service. I believe the reason being is because App Service SDK is still in beta according https://azure.github.io/azure-sdk/releases/latest/mgmt/dotnet.html. But in looking at the quick start and Azure AppService Management client library for .NET, I think it would be something similar to this

    using Azure;  
    using Azure.Core;  
    using Azure.Identity;  
    using Azure.ResourceManager;  
    using Azure.ResourceManager.AppService;  
    using Azure.ResourceManager.AppService.Models;  
    using Azure.ResourceManager.Resources;  
      
    // See https://aka.ms/new-console-template for more information  
    Console.WriteLine("Let's get it started HA!!...");  
    Console.WriteLine("Enter resource group: ");  
    string? resourceGroupName = Console.ReadLine();  
      
    ArmClient client = new ArmClient(new DefaultAzureCredential());  
    SubscriptionResource subscription = await client.GetDefaultSubscriptionAsync();  
    ResourceGroupCollection resourceGroups = subscription.GetResourceGroups();  
    ResourceGroupResource resourceGroup = await resourceGroups.GetAsync(resourceGroupName);  
      
    Console.WriteLine("Getting app services...");  
    await foreach (WebSiteResource webSiteResource in resourceGroup.GetWebSites())  
    {  
        Console.WriteLine($"Web site: {webSiteResource.Data}");  
    }  
      
    WebSiteCollection webSites = resourceGroup.GetWebSites();  
    WebSiteData website = webSites.SingleOrDefault(w => w.Data.Name == "mywebsite")?.Data ?? new WebSiteData(AzureLocation.EastUS);  
    ArmOperation<WebSiteResource> operation = await webSites.CreateOrUpdateAsync(WaitUntil.Completed, "mywebsite", website);  
    

    Now two things, I don't create the app service plan here. This would be dependent on how you intend to deploy resources since you mentioned retrieving an existing resource. Secondly, this snippet doesn't have any deployment. Which again will depend heavily on how you intend to deploy resources; but what I would suggest doing is retrieving WebSiteResource collection, iterating through, and inspecting the Data property to give you an idea on how to setup your objects.

    ---
    EDIT 2022 Aug 18 To benefit the broader community, App Services SDK is currently still evolving. Therefore, there are some gaps and samples aren't ready. However, the team is perceptive to feedback. Follow this GitHub issue for updates and providing feedback.