如何通过Git将.NET Azure WebJob与.NET Core Web App一起部署?

编程入门 行业动态 更新时间:2024-10-19 23:34:10
本文介绍了如何通过Git将.NET Azure WebJob与.NET Core Web App一起部署?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我认为这将是一个非常简单的任务,并且有相当多的文档,但是我没有任何运气,并且假设它几乎都过时了。

我有.NET Core MVC 6 Web App,我一直在开发一段时间,需要在Azure上为它设置一个WebJob。我希望使用持续部署系统将其与应用程序一起部署,Azure规定该应用程序已在使用。根据Kudu文档,这是可能的:

github/projectkudu/kudu/wiki/Web-Jobs#deploying-net-console-webjobs-alongside-an-aspnet-application

其中声明:

这适用于直接从Visual Studio (WebDeploy)或通过git。

它引用此链接( azure.microsoft/en-us/documentation/articles/websites-dotnet-deploy-webjobs/ ),我一直试图跟着没有成功。

我有最新版本的Visual Studio 2015,.NET Core 1.0.0&工具和Azure SDK。

首先变得明显的是,我没有脚手架选项,如Azure文档的屏幕截图所示,并且未能找到任何即使在将所需文件放入指定位置( webjobs-list)之后,也会尝试按照所述方法手动设置它。 json 和 webjob-publish-settings.json )并为我的项目配置它们,并添加 Microsoft.Web.WebJobs发布到WebJob项目,Kudu没有通过持续部署系统找到WebJob。

我尝试了几种方法和变体关于我在那里发现的文档,但我不能让它工作,所有其他问题都是年份。

有人知道我是什么吗?做错了吗?使用.NET Core MVC的最新版本,这甚至还有可能吗?

解决方案

WebJobs的文件存储在'App_Data /作业/连续或App_Data / jobs / triggered文件夹,因此我可以用来部署Web App和WebJob的一种方式是在构建期间手动将所有WebJobs需要的文件复制到这些文件夹。我认为这将适合VS工具更新。

我的解决方案与您的解决方案有点不同,因为我使用Visual Studio Team Services构建和发布我的应用程序到Azure,但概念是一样的。您可以在Visual Studio中使用后期构建事件来运行将这些文件复制到作业文件夹的脚本。

以下是我在VSTS构建中配置的步骤定义: $ b

  • 命令行任务: 工具: dotnet 参数:恢复

  • Visual Studio构建任务: 解决方案: ** \MyApp .sln 平台: $(BuildPlatform) 配置: $(BuildConfiguration) Visual Studio版本: Visual Studio 2015

  • 命令行任务: 工具:dotnet 参数:发布-c $(BuildConfiguration)

  • 命令行任务: 工具:dotnet 参数:发布-c $(BuildConfiguration)$(Build.SourcesDirectory)\src\MyApp.Jobs\project.json

  • 复制文件任务(这是诀窍): 源文件夹: src / MyApp.Jobs / bin / $(BuildConfiguration)/netcoreapp1.0/publish/ 内容: ** 目标文件夹: src / MyApp.Web / bin / $(BuildConfiguration)/netcoreapp1.0/publish/App_Data/jobs/triggered/MyJobName/

  • <存档文件任务: 存档的根文件夹(或文件): src / MyApp.Web / bin / $(BuildConfiguration)/netcoreapp1.0/publish/ 将档案文件路径的根文件夹名称前缀:未勾选 存档类型: zip 创建档案文件:网站.zip 替换现有存档:选中
  • 复制文件任务:源文件夹: 目录: ** / *。zip 目标文件夹: $(Build.ArtifactStagingDirectory)

  • 发布构建工件任务: 路径发布: $(Build.ArtifactStagingDirectory) 工件名称:drop 工件类型:服务器

  • 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:

    github/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 (azure.microsoft/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?

    解决方案

    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

  • 更多推荐

    如何通过Git将.NET Azure WebJob与.NET Core Web App一起部署?

    本文发布于:2023-11-14 04:25:17,感谢您对本站的认可!
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:Azure   NET   Git   WebJob   App

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!