从Visual Studio发布到Azure时,“项目中不存在目标'AddScheduledJob'”

时间:2018-08-23 19:27:17

标签: visual-studio azure azure-webjobs

我的解决方案由一个主要的Web应用程序组成,并附加了一些Azure Web作业。当我去发布主要的Web应用程序时,我收到此错误:

[project_path]\[project_name].csproj(0,0): Error MSB4057: The target "AddScheduledJob" does not exist in the project.

我不确定AddScheduledJob的来源。它不是解决方案中任何项目的名称。

我想我已经找到了“尝试”文件来引用这个幻影项目:

[solution_path]\packages\Microsoft.Web.WebJobs.Publish.1.0.7\tools\webjobs.console.targets

此文件包含以下文本片段:

 <Target Name="AddScheduledJob"
      DependsOnTargets="$(AddScheduledJobDependsOn)"
      AfterTargets="MSDeployPublish"
      Condition="'$(FilePreview)' == 'false' and ('$(WebJobPublishFromWAP)' == 'true' or '$(_DestinationType)' == 'AzureWebSite')">

<CreateScheduledWebJob JobConfig="@(JobConfig)"  
                       WebSiteName="$(WebSiteName)" 
                       WebSiteUrl="$(WebSiteUrl)"
                       ManagementUri="$(WebJobManagementUri)"
                       ManagementCertificatePath="$(ManagementCertificatePath)"
                       ManagementCertificatePassword="$(ManagementCertificatePassword)"
                       ManagementCertificate="$(ManagementCertificate)"
                       ManagementToken="$(ManagementToken)"
                       PublishSettingsPath="$(PublishSettingsPath)"
                       SubscriptionId="$(SubscriptionId)"
                       Condition="'%(RunMode)' == 'Scheduled'"/>

我不知道这是哪里来的,或者为什么会引起问题。我很想只删除该代码段,但是在文件顶部,我阅读了该代码段:

WARNING:  DO NOT MODIFY this file, this file is added to your project automatically...

我可以安全地从“ webjobs.console.targets”文件中删除此代码段吗?还是还有其他可能发生的事情?

更新

我发现,即使出现此错误,我的Web应用程序也已成功发布。这是发布过程结束时日志的更深入视图:

Adding ACLs for path (ringclone-test/App_Data)
Publish Succeeded.
C:\APD\RingClone\packages\Microsoft.Web.WebJobs.Publish.1.0.7\tools\webjobs.console.targets(25,3): Warning MSB4011: "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\WebApplications\Microsoft.WebApplication.targets" cannot be imported again. It was already imported at "C:\APD\RingClone\packages\Microsoft.Web.WebJobs.Publish.1.0.12\tools\webjobs.console.targets (25,3)". This is most likely a build authoring error. This subsequent import will be ignored. [C:\APD\RingClone\TicketProcessor\TicketProcessor.csproj]
C:\APD\RingClone\packages\Microsoft.Web.WebJobs.Publish.1.0.7\tools\webjobs.console.targets(25,3): Warning MSB4011: "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\WebApplications\Microsoft.WebApplication.targets" cannot be imported again. It was already imported at "C:\APD\RingClone\packages\Microsoft.Web.WebJobs.Publish.1.0.12\tools\webjobs.console.targets (25,3)". This is most likely a build authoring error. This subsequent import will be ignored. [C:\APD\RingClone\TicketDistributor\TicketDistributor.csproj]
C:\APD\RingClone\packages\Microsoft.Web.WebJobs.Publish.1.0.7\tools\webjobs.console.targets(25,3): Warning MSB4011: "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\WebApplications\Microsoft.WebApplication.targets" cannot be imported again. It was already imported at "C:\APD\RingClone\packages\Microsoft.Web.WebJobs.Publish.1.0.12\tools\webjobs.console.targets (25,3)". This is most likely a build authoring error. This subsequent import will be ignored. [C:\APD\RingClone\ArchiveIndexer\ArchiveIndexer.csproj]
C:\APD\RingClone\packages\Microsoft.Web.WebJobs.Publish.1.0.7\tools\webjobs.console.targets(25,3): Warning MSB4011: "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\WebApplications\Microsoft.WebApplication.targets" cannot be imported again. It was already imported at "C:\APD\RingClone\packages\Microsoft.Web.WebJobs.Publish.1.1.0\tools\webjobs.console.targets (24,3)". This is most likely a build authoring error. This subsequent import will be ignored. [C:\APD\RingClone\Starter\Starter.csproj]
C:\APD\RingClone\packages\Microsoft.Web.WebJobs.Publish.1.0.7\tools\webjobs.console.targets(25,3): Warning MSB4011: "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\WebApplications\Microsoft.WebApplication.targets" cannot be imported again. It was already imported at "C:\APD\RingClone\packages\Microsoft.Web.WebJobs.Publish.1.1.0\tools\webjobs.console.targets (24,3)". This is most likely a build authoring error. This subsequent import will be ignored. [C:\APD\RingClone\NrtTrigger\NrtTrigger.csproj]
C:\APD\RingClone\packages\Microsoft.Web.WebJobs.Publish.1.0.7\tools\webjobs.console.targets(25,3): Warning MSB4011: "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\WebApplications\Microsoft.WebApplication.targets" cannot be imported again. It was already imported at "C:\APD\RingClone\packages\Microsoft.Web.WebJobs.Publish.1.0.12\tools\webjobs.console.targets (25,3)". This is most likely a build authoring error. This subsequent import will be ignored. [C:\APD\RingClone\DownloadProcessor\DownloadProcessor.csproj]
C:\APD\RingClone\packages\Microsoft.Web.WebJobs.Publish.1.0.7\tools\webjobs.console.targets(25,3): Warning MSB4011: "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\WebApplications\Microsoft.WebApplication.targets" cannot be imported again. It was already imported at "C:\APD\RingClone\packages\Microsoft.Web.WebJobs.Publish.1.1.0\tools\webjobs.console.targets (24,3)". This is most likely a build authoring error. This subsequent import will be ignored. [C:\APD\RingClone\DatabaseReIndexer\DatabaseReIndexer.csproj]
C:\APD\RingClone\packages\Microsoft.Web.WebJobs.Publish.1.0.7\tools\webjobs.console.targets(110,5): Error : An error occurred while creating the WebJob schedule: Webjob configuration is missing metadata for StartTime
C:\APD\RingClone\DailyMaintenance\DailyMaintenance.csproj(0,0): Error MSB4057: The target "AddScheduledJob" does not exist in the project.
C:\APD\RingClone\packages\Microsoft.Web.WebJobs.Publish.1.0.7\tools\webjobs.console.targets(25,3): Warning MSB4011: "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\WebApplications\Microsoft.WebApplication.targets" cannot be imported again. It was already imported at "C:\APD\RingClone\packages\Microsoft.Web.WebJobs.Publish.1.0.12\tools\webjobs.console.targets (25,3)". This is most likely a build authoring error. This subsequent import will be ignored. [C:\APD\RingClone\ScheduledTrigger\ScheduledTrigger.csproj]

如您所见,它说“发布成功”,然后抱怨其中一个作业的“ StartTime”。然后抱怨“ AddScheduledJob”。我不关心“ StartTime”问题。我可以解决的。但是有关名为“ AddScheduledJob”的项目的错误令人困惑。即使发布似乎发生了,我也不希望这个错误使日志混乱。是什么导致此错误?

2 个答案:

答案 0 :(得分:0)

那是一个古老的NuGet软件包。在较早的版本中,如果您将Webjob配置为按计划而不是连续运行,则Visual Studio允许您配置该计划的计划。您可以按照以下指南删除该目标并配置计划:https://docs.microsoft.com/en-us/azure/app-service/web-sites-create-web-jobs#CreateScheduledCRON。如果您使用的是旧版的Visual Studio,请进行升级,以便拥有最新的WebJob项目模板。

答案 1 :(得分:0)

首先,您必须从Nuget添加Microsoft.Web.WebJobs.Publish软件包。即使VS具有“发布到网络作业”操作,它也不会自动将该软件包添加到您的项目中。您可以参考此blog

添加后,您仍然会感到困惑。 VS不会自动修改您的.csproj文件以使用此软件包。 为此,您需要手动修改.csproj文件。最简单的方法是将其卸载到VS中,然后在CSharp目标之后添加以下行–我在上下文中包括了该行:

<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Microsoft.Web.WebJobs.Publish.1.0.11\tools\webjobs.targets" 
Condition="Exists('..\packages\Microsoft.Web.WebJobs.Publish.1.0.11\tools\webjobs.targets')" />

与您类似的issue。当他在asp.net网站上添加新的WebJob时,请保留Microsoft.Web.WebJobs.Publish软件包的较新版本。