Manage Custom App Offline via VSTS publish in Azure - asp.net

I want to manage a custom App offline file whilst doing a publish to azure via the Deploy Azure App Service task.
I realise that this task has a property of:take app offline
however this property will use the basic app offline file which is what I would like to avoid.
I figure I need to do something like this.
Option 1
rename file on azure service _App_Offline.htm to App_offline.htm
publish app.
rename file on azure service App_Offline.htm to _App_Offline.htm
however I can't figure out how to do steps 1 or 3.
Option 2
publish file on azure service App_Offline.htm
publish app.
delete file on azure service App_Offline.htm
I can manage steps 1 and 2 of these but how would i do step 3?
any other options i could try?

You can Create/Delete/Rename file on azure app service through kudu REST API, refer to this thread below to get more information about how to use kudu REST API during the build/release.
Remove files and foldes on Azure before a new deploy from VSTS

Related

How to deploy multiple apps with Azure DevOps?

I have a .NET solution that contains several projects. I want to set up a deployment pipeline in Azure DevOps but I'm not sure how to do this. I want to have 1 pipeline that deploys the following projects:
Main web app -> needs to go to Azure Web Apps
Portal web app -> also needs to go to Azure Web Apps
Database -> needs to be deployed to SQL Azure Database
How do I set this up? I selected the default 'Azure App Service Deploy' template, but in the deployment task I cannot select which project I want to deploy. The package refers to $(build.artifactstagingdirectory)/**/*.zip, but this is a zip file that contains the artifacts for both my web projects (and the database DACPAC is missing here).
that's many questions in one, but I'd generally separate build\release pipelines for each application (that way you have more control) and you dont have the problem of how to select proper zip file. I'm pretty sure you cant even select a part of zip file (since you now have a single zip file with several solutions), so your approach is not going to work.
as for how to set this up: your build should build 1 project exactly and pack\upload it. and then your release will target that artifact and everything will work just fine.
First things first. Copy the build artefacts into 3 different packages. Say,
Artefacts1: For Web Apps
Artefacts2: For Portal Apps
Artefacts3: For DACPAC files
In this case you will have 3 copy files task copying and 3 publish build artefacts task to publish it to Azure DevOps. In the release pipeline, add 3 agent jobs to perform
Deploy to Web App
Deploy to Portal App
Database DACPAC Deploy
You can refer this to have similar pipeline.

How to host a console application on Azure by uploading .exe file?

I have an web application (ASP.NET MVC) host on Azure web app service and an console application (C#) as http trigger locally. This Azure web app service will call the .exe once when it's running. They run well this way.
Now I'd like to move the .exe file to Azure and call it from Azure app service. But I only find Azure function app to execute a piece of code written using Azure portal. Is there a possible solution for me to simply upload this exe file to Azure and can be called by Azure app service ?
Thanks in advance.
It seems that you would call your console application as http trigger when web app run. If so, you may need to upload your console application as a Azure webjob.
You could right click your console app and choose "Publish as Azure Webjobs" to publish your console app to the Web app on Azure.
WebJobs is a feature of Azure App Service that enables you to run a program or script in the same context as a web app.
For more details about deploy webjobs you could refer to this article.
Also, if you are using console core application, you could refer to this blog to deploy it.

How to deploy a solution with two projects to Azure App Service?

I am trying to minimize the cost of running my web app in Azure App Service. I have a Visual Studio 2017 solution with two Web Projects: Web and API (both .NET Core). The entire solution is part of a single GitHub Repo. Before adding the API project, the build and deployment to Azure App Service was automated. My goal is to deploy both projects under the same App Service (to minimize cost) with two subdomains (e.g. www.example.com and api.example.com) and keep everything automated.
Is this something that can be done? Can somebody please help me understand how this can be done? Can those settings be commited?
An Azure App Service Plan can contain multiple web apps. Normally when you use the Azure portal to connect it to source control, Kudu (the tool behind App Service Plans), will create a deployment script for that site.
In case you want to deploy two projects of a single solution (and git repo) to different Web Apps you have to do the following:
Create two web apps under the same App Service Plan
Connect both of them to the same git repo for automated deployments
Modify the deployment parameters
I'm going to suppose you know how to do the first two steps.
To modify the deployment parameters, you could either modify the deployment script by downloading it through Kudu and adapting it or, much simpler, configure it through the portal:
Go the App1 => Application Settings => Add setting PROJECT with value
<path>\<path-to-app1>.csproj
Go the App2 => Application Settings => Add setting PROJECT with value <path>\<path-to-app2>.csproj
Every time you push up a change, both web apps will receive an update, but they will deploy a different part to the web site.
More information can be found here (see last paragraph): https://github.com/projectkudu/kudu/wiki/Customizing-deployments

How to deploy Azure Web Apps using Azure Resource Manager-Based PowerShell?

I want to deploy my Azure web apps using PowerShell. Here is my expected workflow:
Create Package using MSBuild
Deploy the package to Azure
I tried with the approach described in the below link:
https://github.com/gregpakes/DoIHaveGPS/blob/master/PublishScripts/Publish-WebApplication.ps1
I modified the script to use an existing web app instead of creating. So I call something like Get-AzureWebsite -Name $Config.name..
But it never finds the existing app service (web app) due to the subscription issue. I tried so many times to switch the subscription but it's not working. Get-AzureWebsite always keep searching on the old subscription which I don't use anymore.
If I call Get-AzureRmSubscription from powershell I get two subscriptions but if I call Get-AzureSubscription I get only one.
How can I deploy my application packages using powershell using resource manager based powershell?
The cmdlets used by the script you linked to are using the "old" service management interface. If Get-AzureSubscription doesn't return a subscription that means it's only available to use via AzureRM. The AzureRM web app cmdlets don't have a simple "publish" command as the old ones did... So if you wanted to replicate that in PowerShell you could do something like this:
$deploycmd = "$env:ProgramFiles\IIS\Microsoft Web Deploy V3\msdeploy.exe"
$packageLocation = Resolve-Path -Path "C:\users\bjm\downloads\package.zip"
$webAppName = 'myazuresite'
$user = '$myazuresite'
$pass = 'jSjku1lWBdZNgGjyZWYfDhFn4DFfZlAqTq1RjPu5Fnv3yYe9l2Fl5xz5RK0x'
$setParam = "-setParam:name=""IIS Web Application Name"",value=$webAppName"
$dest = "-dest:auto,ComputerName='https://$webAppName.scm.azurewebsites.net:443/msdeploy.axd?site=$webAppName',UserName='$user',Password='$pass',AuthType=Basic"
& $deploycmd "-verb:sync", "-source:package=$packageLocation", $setParam, $dest
I actually prefer juvchan's approach but if you've already got the rest in place via PS this might be easier.
After you've created the web deploy package for your application, you need to create a Azure Resource Manager (ARM) template which allows you to deploy to a Azure web app using the web deploy package.
Then you can use the Azure PowerShell cmdlet below to deploy your ARM template above to achieve what you require.
New-AzureRmResourceGroupDeployment -Name <deployment-name> -ResourceGroupName <resource-group-name> -TemplateUri <ArmTemplateJsonUri>
Useful references:
Deploy a web app with MSDeploy, custom hostname and SSL certificate
Deploy your app to Azure App Service
https://github.com/Microsoft/azure-docs/blob/master/articles/azure-resource-manager/resource-group-template-deploy-cli.md
https://github.com/Microsoft/azure-docs/blob/master/articles/azure-resource-manager/resource-group-template-deploy-cli.md
This topic shows how to use the Azure portal with Azure Resource Manager to deploy your Azure resources. To learn about managing your resources, see Manage Azure resources through portal. Currently, not every service supports the portal or Resource Manager. For those services, you need to use the classic portal. For the status of each service, see Azure portal availability chart.
1. To create an empty resource group, select New > Management > Resource Group.
2. Give it a name and location, and, if necessary, select a subscription. You need to provide a location for the

Deploying ASP.NET Core solution with class library to Azure

I'm working in VS2015 and have a ASP.NET Core solution with two projects - an API Web Project and a Class Library that holds all the data entities, context and Entity Framework migrations. The API project references the class library and all works well on my local machine.
I now want to deploy the solution to Azure and this is where I'm hitting the problem. If I right click on the API project and go through the Azure App Service publish wizard, on the Settings tab I expand Databases and the message is "No databases found for this project" - which I'm guessing is because it can't find a context as it's not in this project.
If I do the same on the CL project though, there is no Azure App Service deployment option, the only option is File System and clearly there's no option to create the database there either.
So, in summary, my question is how I can deploy this type of solution to Azure and have the database created and migrations applied?
I think you need to create the DB first in the azure and then try to publish your application through the wizard. The database is on your local machine and the application will work just fine on your local environment. But on the cloud you have to first create the database on Azure SQL. Then you need to get the SQL connection string from the portal and update your config file accordingly. Once this is done you can then publish your application from Visual Studio. Please note that the wizard will still not show you the databases, but the application, when configured properly will run fine.

Resources