Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to deploy ASP.NET Core websites to Azure using VS Azure Resource Group projects?

I have built, as a proof of concept, an ASP.NET MVC 4.5.2 website with an MySQL database and have deployed this to Azure using an Azure Resource Group project (based on https://azure.microsoft.com/en-us/documentation/articles/vs-azure-tools-resource-groups-deployment-projects-create-deploy/>), which works very well.

I have, however, tried the same with an ASP.NET Core 1.0 website, which doesn't work, at least out-of-the-box - adding a reference from the ARG project to the website project doesn't seem to work properly and no WebDeploy package of the website is created upon deploy. I'm guessing that this will work sometime (perhaps when the Visual Studio tooling for .NET Core graduates) but maybe it is possible today by modifying the generated JSON and Powershell scripts?

like image 462
David Nordvall Avatar asked Oct 27 '16 19:10

David Nordvall


People also ask

How do I deploy ASP NET Core to Azure App service?

Use Visual Studio to create and deploy an ASP.NET Core web app to Azure App Service on Windows. Use the command line to create and deploy an ASP.NET Core web app to Azure App Service on Linux. See the ASP.NET Core on App Service Dashboard for the version of ASP.NET Core available on Azure App service.

Can ASP NET Web Apps be hosted on azure?

ASP.NET web apps are cross-platform and can be hosted on Linux or Windows. When you're finished, you'll have an Azure resource group consisting of an App Service hosting plan and an App Service with a deployed web application. Azure PowerShell is recommended for creating apps on the Windows hosting platform.

How do I publish a project to Azure web app service?

In Solution Explorer, right-click the MyFirstAzureWebApp project and select Publish. In Publish, select Azure and then Next. Choose the Specific target, either Azure App Service (Linux) or Azure App Service (Windows). Then, click Next. When targeting ASP.NET Framework 4.8, use Azure App Service (Windows).

Which version of NET Core is supported on Azure App service?

ASP.NET Core 3.0 is supported on Azure App Service. To deploy a preview release of a .NET Core version later than .NET Core 3.0, use one of the following techniques. These approaches are also used when the runtime is available but the SDK hasn't been installed on Azure App Service.


2 Answers

ASP.NET Core tooling has graduated but there is still no support for ASP.NET Core applications in Azure Resource Group projects. Since I use Visual Studio Team Services för build and release I solved this by simply creating an Azure Web App with the Azure Resource Group project and instead of linking my ASP.NET Core project to the resource group project (which works with ASP.NET 4.5) I let VSTS handle deploying the actual code to the Azure Web App. My release definition has two task:

  1. Azure Deployment:Create Or Update Resource Group (which creates the Azure Web App instance
  2. Deploy Azure App Service (which puts my code in the Azure Web App instance, instead of the placeholder code).
like image 117
David Nordvall Avatar answered Oct 09 '22 10:10

David Nordvall


As per @david-nordvall's answer the support isn't quite there. The issue I have hit is that when you add a reference to an ASP.NET Core project to an Azure Resource Group project, the Visual Studio build fails with:

[error]Deployment.targets(57,5): Error MSB3030: Could not copy the file "obj\Release\ProjectReferences\MyAspDotNetCoreProject\package.zip" because it was not found.

This is the part of the .deployproj file with the reference:

<ProjectReference Include="..\MyAspDotNetCoreProject\MyAspDotNetCoreProject.csproj">
  <Targets>
  </Targets>
  <AdditionalProperties>WebPublishMethod=Package;DeployOnBuild=true;Configuration=Release;PublishProfile=Default;DesktopBuildPackageLocation=..\MyAzureDeployProject\$(ProjectReferencesOutputPath)\MyAspDotNetCoreProject\package.zip</AdditionalProperties>
  <IncludeFilePath>$(ProjectReferencesOutputPath)\MyAspDotNetCoreProject\package.zip</IncludeFilePath>
</ProjectReference>

The problem seems to be the missing targets. Here is a reference to a "classic" ASP.NET project:

<ProjectReference Include="..\MyClassicAspNetProject\MyClassicAspNetProject.csproj">
  <Targets>Build;Package</Targets>
  <AdditionalProperties>PackageLocation=..\MyAzureDeployProject\$(ProjectReferencesOutputPath)\MyClassicAspNetProject\package.zip</AdditionalProperties>
  <IncludeFilePath>$(ProjectReferencesOutputPath)\MyClassicAspNetProject\package.zip</IncludeFilePath>
</ProjectReference>

I thought I'd be clever and manually create the reference to the ASP.NET Core project using the same definition as the "classic" ASP.NET project (substituting the names), but then the build fails with:

error MSB4057: The target "Package" does not exist in the project.

So I simply removed the Package target:

  <Targets>Build</Targets>

And the build failed again! Back to the first error:

error MSB3030: Could not copy the file "obj\Debug\ProjectReferences\MyAspNetCoreProject\package.zip" because it was not found.

But by some off chance, the build had already kicked off in Azure DevOps (got to love building on Pull Requests) and it had succeeded!

The difference in my Azure DevOps build is some extra parameters for MSBuild:

 /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="C:\temp" /p:RunOctoPack=true /p:platform="Any CPU" /p:configuration="Release" /p:VisualStudioVersion="15.0"

I could even run MSBuild locally and it succeeded. I haven't worked out exactly why it's working with the extra parameters.

Hope that helps.

[Update]

It's worth noting that if you've got this far with ASP.NET Core via ARM deployment, you'll need to set the AppOffline property in your MSDeployto true:

"resources": [
    {
        "apiVersion": "2016-03-01",
        "name": "MSDeploy",
        "type": "Extensions",
        "dependsOn": [
            "[concat('Microsoft.Web/Sites/', parameters('appName'))]"
        ],
        "properties": {
            "packageUri": "https://mystorageblob.blob.core.windows.net/package/my_webdeploy_package.zip",
            "dbType": "None",
            "connectionString": "",
            "AppOffline": true,
            "setParameters": {
                "IIS Web Application Name": "[parameters('appName')]"
            }
        }
    }
],

(From here)

The problem is that in ASP.NET Core the files are locked.

like image 22
antmeehan Avatar answered Oct 09 '22 09:10

antmeehan