8
votes

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?

2
can you publish your json and powershell? I have managed to do this but with handcrafted deployemnt scripts, i.e. outside VSDorin
Hi, did you end up figuring this out? By the number of upvotes you have received I'm guessing others would love to know the answer if you found one...dcarson

2 Answers

3
votes

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).
2
votes

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.