使用 VSTS 部署 Azure WebJob

Deploy Azure WebJob using VSTS

我在使用 Visual Studio 团队服务 (VSTS) 部署 Azure WebJob 时遇到了一些问题。

WebJob 似乎已成功部署,但它破坏了托管在同一应用程序服务中的 Azure 网站!如果我使用 VS2013 进行部署,则不会出现此问题。

这是我生成 WebJob 部署包的构建任务:

这是我的部署任务:

部署 Azure WebJob 时没有错误。如果我转到 Azure 门户,我会看到 WebJob 在那里,并且它运行成功。 WebJob 文件按预期复制到 wwwroot\App_Data\jobs\triggered\RemoveExpiredDids 文件夹中,但问题是一些其他文件将被复制到 wwwroot\App_Data\bin 文件夹中,这将破坏已经部署到该应用程序服务中的现有网站! !!

所以我决定找出发生这种情况的原因。下载并解压缩部署包后,我看到有 2 个文件夹(app_databin)和调度程序文件(settings.job):

这解释了为什么某些程序集被复制到应用服务的 wwwroot\App_Data\bin 中。奇怪的是,从 VS2013 部署时不会发生这种情况!!!我查看了 MSBuild 日志并找到了以下行:

Object dirPath ([app service name]\bin) skipped due to skip directive 'SkipBinFolderOnDeploy'.

最后,bin 文件夹在从 VSTS 部署 Azure WebJob 时包含,但在从 VS2013 部署时被排除在外。

所以我的问题是:如何防止在使用 VSTS 时部署 bin 文件夹? 是否有任何 MSBuild parameter/flag 可以执行此操作?

参考这些方式将webjob部署到azure:

  1. 修改 Visual Studio 构建任务以使用 FileSystem 部署 webjob(MSBuild 参数:/p:DeployOnBuild=true /p:WebPublishMethod=FileSystem /p:publishUrl="$(build.artifactstagingdirectory)\WebJob" /p:DeployDefaultTarget=WebPublish
  2. 将删除文件任务添加到发布定义以删除 bin 文件夹(源文件夹:$(System.DefaultWorkingDirectory)/WebJobVnext/drop/WebJob);内容:bin)
  3. 修改 Azure 应用服务部署任务(1.取消选中使用 Web 部署发布选项。2.包或文件夹:$(System.DefaultWorkingDirectory)/[artifact name] /drop/WebJob

我也遇到过这个问题。

我找到的最新方法是使用 Web Deploy Operation Settings , -skip:Directory= (in this case it would be -skip:Directory='\bin') when you create your azure deploy task in the release definition (Additional arguments). I've seen that this indeed excludes the bin folder from the update actions (result).

如果这对您有任何帮助,请告诉我。

我终于能够修复它,感谢@starain-MSFT 为我指明了正确的方向。不过,我不得不做一些小改动。这是创建部署包的任务:

MSBuild 参数:

/p:DeployOnBuild=true /p:WebPublishMethod=FileSystem /p:DeployDefaultTarget=WebPublish /p:Configuration=$(BuildConfiguration) /p:OutputPath=.\bin\ /p:publishUrl="$(build.artifactstagingdirectory)\temp\WebJob"

这里与@starain-MSFT 答案相比的不同之处在于我必须添加 /p:OutputPath= 参数,否则我会收到以下错误:

The OutputPath property is not set for project

生成包后,我删除了 bin 文件夹并将其压缩(这减少了构建时间)。

这是我的部署任务:

请注意,$(DeploymentPackagePath) 是包含部署包的 zip 文件的路径,如前所述。将包部署为 zip 文件或者解压缩并部署文件夹都没有关系,这两种方式都有效。