I thought this would be a pretty straightforward task and there is quite a bit of documentation out there but I've had zero luck with any of it and am assuming that it is pretty much all out of date.
I have .NET Core MVC 6 Web App that I've been developing for a while and need to set up a WebJob for it on Azure. I want to deploy this alongside the app using the continuous deployment system Azure provides that the app is already using. According to Kudu docs it's possible:
https://github.com/projectkudu/kudu/wiki/Web-Jobs#deploying-net-console-webjobs-alongside-an-aspnet-application
Which states:
This works both when deploying directly from Visual Studio (WebDeploy), or via git.
It references this link (https://azure.microsoft.com/en-us/documentation/articles/websites-dotnet-deploy-webjobs/), which I've been attempting to follow with no success.
I have the latest version of Visual Studio 2015, .NET Core 1.0.0 & Tools and the Azure SDK.
First thing that becomes apparent is that I do not have the scaffolding options as shown in the screenshots on the Azure docs and after failing to find any missing dependencies I resorted to trying to set it up manually as described.
Even after putting the required files in the locations specified (webjobs-list.json
and webjob-publish-settings.json
) and configuring them for my project, and adding Microsoft.Web.WebJobs.Publish
to the WebJob project, Kudu does not find the WebJob via the continuous deployment system.
I've tried several approaches and variations based on the documentation I've found out there but I just can't get it working and all other SO questions are year(s) old.
Does anyone know what I'm doing wrong? Is this even still possible with the latest version of .NET Core MVC?
NET Core WebJob to Azure App Service from Visual Studio uses the same tooling as publishing an ASP.NET Core app. In Solution Explorer, right-click the project and select Publish. In the Publish dialog box, select Azure for Target, and then select Next. Select Azure WebJobs for Specific target, and then select Next.
Deploy WebJobs by using the Azure portal to upload an executable or script. You can run background tasks in the Azure App Service. If instead of the Azure App Service you are using Visual Studio 2019 to develop and deploy WebJobs, see Deploy WebJobs using Visual Studio.
For which web app can you configure a WebJob? Publishing a . NET Core WebJob to App Service from Visual Studio uses the same tooling as publishing an ASP.NET Core app.
WebJobs' files are stored under the 'App_Data/jobs/continuous' or 'App_Data/jobs/triggered' folders, so one way I could use to deploy both Web App and WebJob is manually copying all WebJobs' files needed to these folders during build time. I think this will fit while VS tooling is being updated.
My solution is a little different from yours since I'm using Visual Studio Team Services to build and release my app to Azure, but the concept is the same. You can use a post build event in Visual Studio to run a script that copies these files to the jobs' folder.
Below are the steps I've configured in VSTS build definition:
Command Line task: Tool: dotnet Arguments: restore
Visual Studio Build task: Solution: **\MyApp.sln Platform: $(BuildPlatform) Configuration: $(BuildConfiguration) Visual Studio Version: Visual Studio 2015
Command Line task: Tool: dotnet Arguments: publish -c $(BuildConfiguration)
Command Line task: Tool: dotnet Arguments: publish -c $(BuildConfiguration) $(Build.SourcesDirectory)\src\MyApp.Jobs\project.json
Copy Files task (this is the trick): Source folder: src/MyApp.Jobs/bin/$(BuildConfiguration)/netcoreapp1.0/publish/ Contents: ** Target folder: src/MyApp.Web/bin/$(BuildConfiguration)/netcoreapp1.0/publish/App_Data/jobs/triggered/MyJobName/
Archive Files task: Root folder (or file) to archive: src/MyApp.Web/bin/$(BuildConfiguration)/netcoreapp1.0/publish/ Prefix root folder name to archive path: unchecked Archive type: zip Archive file to create: website.zip Replace existing archive: checked
Copy Files task: Source folder: Contents: **/*.zip Target folder: $(Build.ArtifactStagingDirectory)
Publish Build Artifacts task: Path do publish: $(Build.ArtifactStagingDirectory) Artifact Name: drop Artifact type: Server
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With