Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
491 views
in Technique[技术] by (71.8m points)

asp.net mvc - How do I deploy an Azure WebJob alongside a .NET Core Web App via Git?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

  1. Command Line task: Tool: dotnet Arguments: restore

  2. Visual Studio Build task: Solution: **MyApp.sln Platform: $(BuildPlatform) Configuration: $(BuildConfiguration) Visual Studio Version: Visual Studio 2015

  3. Command Line task: Tool: dotnet Arguments: publish -c $(BuildConfiguration)

  4. Command Line task: Tool: dotnet Arguments: publish -c $(BuildConfiguration) $(Build.SourcesDirectory)srcMyApp.Jobsproject.json

  5. 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/

  6. 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

  7. Copy Files task: Source folder: Contents: **/*.zip Target folder: $(Build.ArtifactStagingDirectory)

  8. Publish Build Artifacts task: Path do publish: $(Build.ArtifactStagingDirectory) Artifact Name: drop Artifact type: Server


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...