更新时间:2023-02-14 16:55:44
有一种方法可以实现,它可以在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.
App_Data/Jobs/Continuous/TheJob
.将run.cmd
文件添加到上面的文件夹,其内容如下:
App_Data/Jobs/Continuous/TheJob
.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>
希望它会有所帮助:)