Deploy .Net Core WebApp to Azure

I created a .Net Core 2.2 Web App in Visual Studio and was able to access the Swagger and resource operations in IIS Express after hitting F5. Next I published the web app to Azure, but first it wouldn’t even run and then it said neither the Swagger page nor the resource methods could be found. Example:

I made two changes. First I added a web.config file and uncommented the System.webServer section (which was added by default).

<?xml version="1.0" encoding="utf-8"?>
  <!-- To customize the core module uncomment and edit the following section. 
  For more info see -->
      <remove name="aspNetCore" />
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
    <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess">
        <environmentVariable name="ASPNETCORE_HTTPS_PORT" value="44361" />
        <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />

Next, after receiving the message the ProductService.xml file could not be accessed, I changed the build action of the file to Embedded Resource so that the file was actually copied to the wwwroot file of the Azure Web App

Note that the ProductService.xml file must be recreated on every build. You can achieve this by setting the following Build property on a Visual Studio project:

When neither of these changes work, you can also open the project file via the Windows Explorer and check if the following property group is present. This property section should be added automatically when creating a .Net Core Web Application, but you can double check. If not present , you could add it.

    <UserSecretsId>See properties window of Visual Studio project</UserSecretsId>

After making those changes, it also worked in Azure. Joehoe! In my case, I forgot to generate documentation file ProductService.xml. You might be wondering why the .Net Core service was still running in IIS Express. The reason for this is, that there’s also a copy of ProductService.xml created in folder bin\Debug\netcoreapp2.2.

A final sidenote has to do with the creation of the publish profile. For some reason I could not select my subscription anymore. Apparently this is a bug. The workaround is to create an empty web app via the Azure Portal. Next save the Publish Profile from the Portal. Now create a new Publish Profile. Select the file type you want to create, ie an Azure App Service. In the bottom left corner of the Publish dialog, you will see a link to import the Publish Profile saved from the Azure Portal. Now your publish profile is actually created.