Is there a way to publish a webjob on azure with a different target framework than the publish project?

143 views Asked by At

I have an azure web application in which I want to update a webjob project to target framework .net 7 but leave the web site at .net 4.7.1 due to legacy constraints on the project.

Is it possible to deploy webjobs with different target frameworks than the web site? If not, is there a better way to approach this problem?

I tried updating the webjob project to .net 7 and deploying, but I the following error when I deploy a webjob to azure that has a different target framework (.net 7.0) than the website (4.7.1).

[12/12/2023 01:07:43 > 0f00b5: ERR ] You must install or update .NET to run this application. [12/12/2023 01:07:43 > 0f00b5: ERR ] [12/12/2023 01:07:43 > 0f00b5: ERR ] App: C:\local\Temp\jobs\continuous\WebJobs\2vgixjvc.b00\WebJobs.exe [12/12/2023 01:07:43 > 0f00b5: ERR ] Architecture: x64 [12/12/2023 01:07:43 > 0f00b5: ERR ] Framework: 'Microsoft.WindowsDesktop.App', version '7.0.0' (x64) [12/12/2023 01:07:43 > 0f00b5: ERR ] .NET location: C:\Program Files\dotnet

Changing the Web App configuration to .net 7 does not seem to make a difference.

Webjob project file as requested: Webjob Project File

Webjob program.cs Program.cs for webjob

1

There are 1 answers

3
Harshitha On

Is it possible to deploy webjobs with different target frameworks than the web site?

If you want to deploy to any other Version of .NET other than the existing website, Follow the below steps.

  • Create an Azure App Service with .NET 7.

enter image description here

  • From Visual Studio, Publish to Web Job enter image description here select the already created App Service (with .NET7 Core version) and deploy the app. enter image description here

You must install or update .NET to run this application.

If you get this error with Framework website hosted in .Net Core,try to install the `ASP.NET Core 7.0 Runtime extension.

enter image description here

As per this MSDoc,

The way that you deploy a WebJobs project is different for .NET Core projects than for .NET Framework projects.

I tried updating the webjob project to .net 7 and deploying

Migrating from .NET Framework to .NET Core requires manual work.

  • .Net Core requires appsettings.json file to add the Connection String (related to WebJob).In .Net Framework app your connection strings are stored in App.config file.

  • Even .csproj in framework app contains additional settings which are not required for Core Apps, even those have to be edited.

  • AFAIK,It is better to create a separate Core Application and add the existing Functions/Jobs to it.

Update

  • For .NET Framework Applications, Publish as Azure Web Job can be seen just below the Publish option.

enter image description here

  • Whereas in Console .NET 7 Core app, the option is available under

Publish => Add a publish profile=> Azure => Azure WebJobs

enter image description here enter image description here