Creating a zipped deployment for an ASP.NET Core web application
When I deployed the ASP.NET Web API services to our Azure hosting endpoint, I needed to create a zipped deployment file to do this. Azure then unzips the contents of this file and deploys it into your hosting slot. I needed to do the same thing recently with our ASP.NET Core 2.0 web application.
Just to clarify, I am using Team Foundation Services (TFS) for all our builds and releases. I much prefer using a build server than to deploy straight from Visual Studio. Yes I know this is entirely possible, but I prefer to keep the build and deployment lifecycle separate from the development lifecycle. I find this leads to greater efficiency, particularly when you have a team of developers who need to collaborate on the same code.
When I did this previously with the ASP.NET Web API project, I used an MSBUILD task from TFS and used the argument /t:publish,package to force the creation of the zipped deployment file. However, the /t:package argument does not exist for ASP.NET Core projects. So how do you create the zip file needed to deploy your web application to Azure.
Well it seems that there a couple of ways to achieve this (although they don’t seem to be fully documented anywhere that I can find). I had to resort to reading through Stackoverflow to find the answer. You can either use MSBUILD or dotnet build. As the arguments that are passed to dotnet build are ultimately passed into MSBUILD (yes it is good old MSBUILD that sits underneath dotnet build), I decided to opt for using MSBUILD. I am also much more familiar with MSBUILD having used it for many years building many other applications.
The MSBUILD statement that worked for me is the following.
Hide Copy Code
"Path\To\MSBuild\MSBuild.exe" /p:configuration="release";platform="any cpu";WebPublishMethod=Package;PackageFileName="\MyFolder\package.zip";DesktopBuildPackageLocation="\MyFolder\package.zip";PackageAsSingleFile=true;PackageLocation="\MyFolder\package.zip";DeployOnBuild=true;DeployTarget=Package
I have this command in a batch file which I then run under TFS as a build step. This build step is one of the last steps in the build process because it only needs to run prior to the release process.