使用WebJob发布简单的Asp.Net Core App(.Net Framework) [英] Publish simple Asp.Net Core App (.Net Framework) with WebJob

查看:228
本文介绍了使用WebJob发布简单的Asp.Net Core App(.Net Framework)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个简单的ASP.NET Core Web应用程序(.NET Framework),并将WebJob与它一起发布到Azure.

I would like to create a simple ASP.NET Core Web Application (.NET Framework) and publish a WebJob alongside it to Azure.

我正在使用Visual Studio 2017,但结果似乎在VS2015中是相同的.

I'm using Visual Studio 2017, but the result seems to be the same in VS2015.

首先,我在VS2017中创建相应的项目:

To start, I create the corresponding project in VS2017:

我选择基本的Web应用程序模板:

I select the basic web application template:

这时我有点迷路了.在较旧的Asp.Net MVC 5方法中,我曾经能够单击Asp.Net项目并找到添加=>新的Azure Webjobs项目".然后,WebJob将始终在发布中被链接,而仅仅是工作".

At this point I get a bit lost. In the older Asp.Net MVC 5 approach, I used to be able to click on the Asp.Net project and find "Add => New Azure Webjobs Project". The WebJob would then always be linked in publishing and just "work".

使用新的Asp.Net Core方法,我似乎找不到一种类似的简便方法来实现这一目标.

With the new Asp.Net Core approach, I can't seem to find an analogously-easy way to get this happening.

我尝试将WebJobs项目手动添加到解决方案中,然后在Asp.Net项目中手动设置webjobs-list.json文件,但是发布步骤无法识别它.我注意到了各种答案,例如 this一个,建议您进入发布过程以复制文件,但是添加到* .pubxml文件的标记没有任何影响(即,未复制文件).

I tried manually adding a WebJobs project to the solution and then manually setting up the webjobs-list.json file in the Asp.Net project, but the publish step didn't recognize it. I noticed various answers like this one which suggest hooking into the publishing process to copy the files, but the markup added to the *.pubxml file didn't have any affect (i.e. the files weren't being copied).

关于此任务,似乎有一些过时的信息.也许有人可以详细说明针对Visual Studio中包含Asp.Net Core应用程序的新解决方案执行此操作的当前过程吗?

It seems that there's a bit of outdated information around regarding this task. Might somebody be able to detail the current process of doing this for a new solution containing an Asp.Net Core app in Visual Studio?

推荐答案

有一种方法可以实现,它可以在VS 2015和project.json中正常工作(甚至允许您从VSTS生成和部署到Azure,而无需任何操作)修改),并且可以在VS 2017中使用-从VS发布可以按预期工作,但是在没有添加一些其他构建步骤的情况下,我无法使其在VSTS上正常工作.

There is a way to do it, it works fine with VS 2015 and project.json (and even allows you to build and deploy to Azure from VSTS without any modifications), and kinda works in VS 2017 - publish from VS works as expected, but I didn't manage to make it work on VSTS without adding some additional build steps.

  1. 照常创建Web应用程序项目,而无需任何其他与Webjob相关的文件.
  2. 为Webjob创建.NET Core控制台应用程序.
  3. 为Web应用程序项目中的Web作业创建必要的文件夹.对于名为TheJob的连续Web作业,应为App_Data/Jobs/Continuous/TheJob.
  4. run.cmd文件添加到上面的文件夹,其内容如下:

  1. Create web app project as usual, without any additional webjob related files.
  2. Create .NET Core console app for webjob.
  3. Create necessary folders for webjob in web app project. For continuous webjob named TheJob it should be App_Data/Jobs/Continuous/TheJob.
  4. Add run.cmd file to above folder with content like:

@echo off
The.Job.Project.Name.exe

  • 在Web项目的project.json文件中,添加以下脚本:

  • In web project's project.json file, add following scripts:

    "scripts": {
      "postpublish": [
        "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%",
        "dotnet publish ..\\Web.Job.Project.Name\\ -o %publish:OutputPath%\\app_data\\jobs\\continuous\\TheJob\\"
      ]
    }
    

  • 诀窍在第二个脚本中-它直接将webjob项目发布到Web应用程序的App_Data目录中,因此可以与网站一起发布.

    The trick is in the second script - it publishes webjob project directly into web app's App_Data directory, so it gets published with the website.

    将项目转换为VS 2017格式后,脚本将进行转换,但不幸的是无法正常工作,webjob文件未发布.

    After converting projects to VS 2017 format, the scripts are getting converted, but unfortunately don't work, webjob files aren't published.

    我发现使其部分起作用的一种方法是将webjob发布到Web应用程序的临时发布目录,因此稍后将其拾取并从VS发布,但是不幸的是,仅当直接从Visual Studio发布时,它才起作用. 它不适用于VSTS版本.

    One way I found to make it partially work is to publish webjob to web app's temporary publish directory, so it is picked up later and published from VS, but unfortunately it works only when publishing directly from Visual Studio. It doesn't work with VSTS builds.

    要执行此操作,请将以下部分添加到Web应用程序的项目文件中:

    To do it, add following section to web app's project file:

    <Target Name="PostpublishScript" AfterTargets="Publish">
      <Exec Command="dotnet publish ..\Web.Job.Project.Name\ -o $(ProjectDir)obj\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\PubTmp\Out\App_Data\Jobs\Continuous\TheJob" />
    </Target>
    

    希望它会有所帮助:)

    这篇关于使用WebJob发布简单的Asp.Net Core App(.Net Framework)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆