Changing the target framework in an Azure web app - azure

I would like to publish an ASP.NET Core 2.1 website to Azure using an Azure Web App to host it. When creating the Azure Web App on the Azure portal, one of the settings is "Runtime Stack". In this case I would set it to ".NET Core 2.1" to match the framework my code is currently using. However once the web app is created, I do not see an option to edit this setting anywhere on the Azure portal, so how would I change it if necessary in the future?
For instance, if I were to later update my application code to use ASP.NET Core 2.2, how would I change the runtime stack of the Azure web app to ".NET Core 2.2"? Is there a setting to edit this in some area of the Azure portal? Or does the Azure web app look at the code (possibly the .csproj file), and automatically update the target framework internally, thus ignoring any settings anyway? Or would I need to delete the web app and create a new one with the correct settings? (If I would need to delete the web app and create a new one, is there some recommended approach to plan for this situation and reduce downtime? Would it be possible to update the staging slot to a newer runtime stack from the production slot, and then do a swap?)

At least for Linux hosts, the runtime stack is available via the app service settings - it is just split up into multiple properties:
On a more technical note, it can be accessed via LinuxFxVersion:
"siteProperties": {
"metadata": null,
"properties": [
{
"name": "LinuxFxVersion",
"value": "DOTNETCORE|2.1"
},
{
"name": "WindowsFxVersion",
"value": null
}
],
"appSettings": null
},
E.g. via Azure CLI:
az webapp config set -g MyResourceGroup -n MyUniqueApp --linux-fx-version DOTNETCORE|2.1
If you want to avoid downtimes, you should use slots like you mentioned. Like every app deployment, you will have a very slow application for a short while during the deployment.
Changing everything in one go is possible if you use something like Azure Pipelines. The Azure App Service Deploy Task allows you to both deploy the application an set the runtime stack at the same time.
Slots are very much independent from each other, so you can have different runtime stacks depending on the slot.

Step 1 - Set the target framework for the project
In the project set the target framework to the one you want. In VS, right click the project name, choose Properties, then specify the target framework.
Or directly edit the .csproj file to specify target framework, using the following syntax
<TargetFramework>netcoreapp3.1</TargetFramework>
Step 2 - Set the target framework for publishing
When publishing the project, set the target framework there as well. In VS, right click the project name, choose Publish, and in the publish wizard specify the target framework.
This setting will be reflected in the .pubxml file as well (and can be edited there instead if you prefer using the syntax <TargetFramework>netcoreapp3.1</TargetFramework> )
Step 3 - Check that the runtime you need is present on Azure
If the runtime version specified in the project and publish settings is present on Azure, then that version will be used automatically. So we need to check if it is present.
Alex described how to do this on Linux hosts in his answer but that does not work on Windows hosts (the 'Major Version' and 'Minor Version' settings are not displayed for Windows hosts on the Azure portal).
The Kudu console on the other hand works for both operating systems. Kudu can be reached at https://<app_name>.scm.azurewebsites.net. There are a couple of different ways to look up runtime versions Kudu -
Option 1. Click the 'Runtime versions' link in the Rest API section.
It will
display the supported dotnetcore versions (and also nodejs versions,
os version, etc).
Option 2. Click Debug Console -> CMD to launch the kudu
command prompt. Type in dotnet --list-runtimes.
(Do not use dotnet --list-sdks because what is important is the runtime, not the sdk, since the sdk is needed for building an app and most likely you will build the app on your local machine before publishing to Azure).
Step 4 - If the runtime is not present on Azure
This might be the case if the runtime you are using is still in preview. You can either embed your own .net core version with the application or you can use an extension. These are described by Sebastien in his answer.
Step 5 - Publish the app
There is no need to delete the existing web app and create a new one. You can publish to an old app that was previously using a lower target framework.

Previous answer is correct, you can manage runtime version in Application Settings Configuration.
But, you can also run dotnet publish --runtime win-x86 to embed your own .Net Core version with your application.
It adds some overhead but you control runtime version.
.NET Core RID Catalog
A third option is to install a Site Extension

Related

Switching one Azure App Service's codebase for different one after .NET Core version rewrite

We have a .NET Core 2.1 Web App on Azure as an App Service. We deploy it to Azure via Visual Studio 2017's publish option (though it is also in a Git repo). It has a bunch of custom domains and SSL on all of them provided by Azure.
We've written a new version of the web app in .NET Core 3.1, in VS 2019. Identical functionality but written from the ground up rather than trying to upgrade the existing 2.1 version.
There's no staging version online as such - instead we develop on local machines and then just use test domains online that use the same service but where the environment is switched to use dev DBs and bucket locations etc, which is one of the reasons to write a new app rather than upgrade it, also, it just seemed cleaner and I saw that people had some issues when doing upgrades...
Is there an easy way to switch/publish the new web app/code into the current Azure App Service, to replace the old one? Or will I need to create a new App Service and then create all the custom domains, SSL etc there after removing them from the old one?
Or could I perhaps switch to git deployment and push the entire new project in over the old one - would that work or just create some kind of disaster?
There is usually no issue when pushing a new application version to your app service, even if it uses a new version of .NET Core.
You have to consider two things:
Windows AppService Plan: .NET Core 3.1 runtime has been rolled out worldwide, while the SDK has not (yet). When in doubt, use self-contained deployment.
Linux AppService Plan: You need to select the desired runtime version in the portal. Using e.g. Azure Pipelines you can set the runtime version at the same time as you publish the new version. Not sure how VisualStudio handles this.
As a general recommendation, you should follow silents suggestion of using slot deployments to have as little impact for your customers as possible. Each slot can have e.g. a different .NET runtime version, so you can test everything on the staging slots.

Site does not show when deployed to azure app service

I am trying to deploy a simple "Hello World!" .NET Core MVC 3.1 web application to an Azure App Service using the Azure Portal Deployment Center.
I created a my application using .Net Core version 3.1. (Visual Studio 2019 only has version 3.1 in the drop down, not 3.0.)
Visual Studio 2019 create wizard dropdown:
However this is not yet supported in the Deployment Center. You can select a runtime stack 3.1 (LTS) when adding creating the App Service Plan, but when you try and create a CI/CD pipeline with the Deployment Centre, it gives an error: "source.buildConfiguration.version: Property 'source.buildConfiguration.version' has invalid/unsupported value 'LTS'"
If I downgrade my web application to a version 3.0, and create the App Service/deployment pipeline with 3.0 using the Azure Portal Deployment Centre (building from my Azure Repo), it says the deployment has been successful, but it still shows the default site, not my "Hello World!" site.
Azure Devops Services indicates that the deployment has been successful:
Therefore, I expect to see my "Hello World!" site:
However, it still shows default site:
Given that there are no error messages, I'm not sure how best to debug what has gone wrong with the deployment. Any advice would be appreciated.
I ran into the same issue today... The solution was to change the
Startup Command (dotnet "myApp.dll" instead of dotnet run "myApp.dll")
under Configuration - General Settings in the App Service.
You might also check the Log Stream in your App Service for additional errors.
I also had to adjust the CD pipline task "Deploy Azure App Service" in Azure Devops to the Same Startup command.
Change .NET version to v4.8. Azure by default set it to v3.5, even though I selected 4.8 in the AppService wizard. My website uses v4.6.1.
And also, you have to change the document order in the configuration settings - default documents, in order to work and show the project enter image description here

How do I package and deploy a single Azure web app containing several virtual apps from Visual Studio Team Services (previously VS Online)?

I have a Visual Studio solution that contains two web applications (our main site and our WebAPI project). I am able to host them locally in IIS Express as a single site using the applicationhost.config, but I want to package them (in our Build) and then deploy them (in our Release) as a single site from Visual Studio Online (which hosts our code) to Azure.
My Visual Studio Team Services Build configuration packages each of the Visual Studio projects into its own Web Deploy package. The Web Deploy packaging is done during my Build phase, and the deployment to Azure is done during the Release phase - this is done so I am not recompiling source every time I do a deployment, which is unnecessary and would slow down the process.
The first web application identifies "HelloAzure" as the DeployIisAppPath in its pubxml file. The second one (the WebAPI project) identifies "HelloAzure/api" as the DeployIisAppPath in its pubxml file.
Currently, I am using two of the "Azure Web Site Deployment" steps (the one that uses Service Endpoints to perform a deployment). I name the same web app name for both steps. When the second project is deployed, it seems to overwrite the first one rather than adding a second application to the existing site. I believe I must not be following the intended practice for deploying several Web Deploy packaged applications into one web site from Visual Studio Team Services to Azure, but I can't find the recommended practice documented anywhere.
I do need to have both applications hosted within a single site. Deploying them as separate sites is not an option.
It appears that Kudu has some options that might support this scenario, but I am not deploying from source code, I am deploying from Web Deploy packages created by our Team Services build.
The MSDeployAllTheThings VSTS extension supports deployment to a virtual app in an Azure site.
https://marketplace.visualstudio.com/items?itemName=rschiefer.MSDeployAllTheThings
Microsoft also seems to have added official support for deploying to virtual apps from VSTS to Azure to the AzureRM VSTS extensions according to this thread: https://github.com/Microsoft/vsts-tasks/issues/624

How to publish the Console Application (package from asp.net 5) as an Azure Web Job

I have a new ASP.NET 5 application (beta 8) and I have created a console application (the new Package version). I have followed this guide by Microsoft on publishing it to Azure Web Jobs. The guide is based on 2013 and do not use vNext, but it describes all the files, etc. that are required to publish the webjob. I have followed it and created:
webjob-publish-settings.json
added reference to Microsoft.Web.WebJobs.Publish
added webjobs-list.json (with reference to .xproj)
After I do publish my web application, no job appears (so I guess it just does not use the config properly). There is no context menu to Publish As WebJob either on the console application.
Is there any proper way to overcome it or we'll have to wait till full release of ASP.NET 5 to have it fixed and I have to create an ordinary console application meanwhile? I hope there is some workaround to publish it at least manually.
Currently, there is no support in VS to deploy DNX WebJobs. This will come later, but until then there are still ways to deploy manually.
Related reading:
http://ahmelsayed.com/running-dnx-based-webjobs/
publish dnx based WebJob with local dependencies

VSO Continuous Deployment Fails w/ Multiple Sites in Web Role

I have configured a cloud service to run multiple web applications in one web role. More information on this is in the documentation.
The documentation does not appear to be correct for local builds with the Azure 2.3 SDK. Apparently, since SDK 1.8, the physicalDirectory attribute is not relative to the Azure cloud service project folder, but its output folder. Also see this question. By changing the path to ../../../Project.Name the service can be built and deployed locally from VS2013 with SDK 2.3.
We also use continuous integration on Visual Studio Online. However, the project now fails to build with the message that the path to my second web project is invalid. The path it's trying to use is C:\Project.Name\. I don't think this is quite correct.
I have tested with ../Project.Name as the physicalDirectory attribute value on VSO, but that also fails.
Is it a matter of somehow correctly configuring this for Visual Studio Online, or is it simply not currently supported?

Resources