Home > Software engineering >  Deploy Azure App Service with multiple Virtual Applications using Visual Studio 2022
Deploy Azure App Service with multiple Virtual Applications using Visual Studio 2022

Time:12-30

I currently am using Azure Cloud Service (classic) and am able to effectively deploy a WebApp that contains 4 virtual applications using an Azure Cloud Service project. My ServiceDefinition.csdef file looks like:

<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="My.Azure.Web.API" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" schemaVersion="2015-04.2.6">
  <WebRole name="My.Web.API" vmsize="Small">
    <Sites>
      <Site name="Web" physicalDirectory="{path to My.Web.API}">
        <VirtualApplication name="webapp1" physicalDirectory="{path to My.Web.WebApp1}" />
        <VirtualApplication name="webapp2" physicalDirectory="{path to My.Web.WebApp2}" />
        <VirtualApplication name="webapp3" physicalDirectory="{path to My.Web.WebApp3}" />
        <VirtualApplication name="webapp4" physicalDirectory="{path to My.Web.WebApp4}" />
        <Bindings>
          <Binding name="Endpoint1" endpointName="Endpoint1" />
          <Binding name="HttpsIn" endpointName="HttpsIn" />
        </Bindings>
      </Site>
    </Sites>
    <Endpoints>
      <InputEndpoint name="Endpoint1" protocol="http" port="80" />
      <InputEndpoint name="HttpsIn" protocol="https" port="443" certificate="{certname}" />
    </Endpoints>
    <Imports>
      <!--<Import moduleName="Diagnostics" />-->
      <Import moduleName="RemoteAccess" />
      <Import moduleName="RemoteForwarder" />
    </Imports>
    <ConfigurationSettings>
      
    </ConfigurationSettings>
    <Certificates>
      <Certificate name="{certname}" storeLocation="LocalMachine" storeName="My" />
    </Certificates>
  </WebRole>
</ServiceDefinition>

I am working on migrating to Azure App Service and despite some significant digging I can not seem to find an equivalent/similar deployment process in Visual Studio for multiple Virtual Applications in Azure App Service.

I have found numerous posting that indicate using the publish function in the actual WebApp projects, but I would have to perform 4 separate deployments instead on one. And need to pre-define the virtual directories in the App Service configuration. Under the current approach, virtual applications/directories are defined during the deployment.

I plan to eventually move to Azure DevOps Pipelines for CI/CD and hope there is a mechanism to achieve this, but for now would just like something functional from Visual Studio.

Is there an equivalent/similar deployment process in Visual Studio for multiple Virtual Applications in Azure App Service? If not, what are the options?

Apologies if this a re-tread. I did my due diligence with no definitive answers. Unless of course the answer is right in front of me!? Thanks for your time!

Eric

CodePudding user response:

Check the below steps to deploy multiple Virtual Applications to Azure App Service from Visual Studio 2022.

  • Create a new App Service in Azure Portal.

enter image description here

  • In App Service Overview, click on the Download publish profile.

enter image description here

  • In VS 2022, create Applications of your desired framework. I have taken .NET Core Apps as an example.

Visual Studio Project Folder Structure

enter image description here

The option to create Virtual Directories in Azure Portal is available only for Azure Windows App Service.

  • In Azure Portal => App Service => Configuration => Path mappings => Under Virtual applications and directories create New Virtual application.

enter image description here

  • Make sure the Virtual Path is same as Web App Name in VisualStudio.

Publish each Application in VS to Azure App Service using the Downloaded Publish Profile.

  • Right click on the 1st WebApp Project => Publish => Add a publish profile => Import Profile.

enter image description here

  • Browse and upload the Publish Profile which we have downloaded from Azure Portal App Service.

enter image description here

  • Change the settings of the Application.
  • The site name must be the App Service name/VirtualPathName which we have created in portal. Ex: Here it is VirtualApps29Dec/WebApp1.

enter image description here

  • Save and continue with next steps to publish the App.

  • Follow the same steps with the same Publish Profile for WebApp2, WebApp3 and WebApp4 as well.

Deployed Azure App Service Structure in KUDU Console

enter image description here

The Url's for the Applications will be

https://virtualapps29dec.azurewebsites.net/WebApp1
https://virtualapps29dec.azurewebsites.net/WebApp2
https://virtualapps29dec.azurewebsites.net/WebApp3
https://virtualapps29dec.azurewebsites.net/WebApp4

Initially When I tried to access the Applications, I got the below error.

enter image description here

When I check the Web.config of the deployed Applications, I can see the below code.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\WebApp2.dll" stdoutLogEnabled="false" stdoutLogFile="\\?\%home%\LogFiles\stdout" hostingModel="inprocess" />
    </system.webServer>
  </location>
</configuration>
<!--ProjectGuid: c238430b-40de-45d7-bbb7-ad96da7c4dc4-->
  • AspNetCoreModuleV2 will not allow multiple In-process virtual apps within the same app service plan.

  • I have resolved the issue by changing AspNetCoreModuleV2 to AspNetCoreModule

  • Edit all the Web.config files under the deployed Applications.

enter image description here

Output :

enter image description here

  • Related