MS Deploy task failed DeploymentBaseOptions does not contain a definition for UserAgent

…衆ロ難τιáo~ 提交于 2019-12-05 02:15:53

I faced the same issue. For me the solution was to install Web Deploy 3.5 (http://www.iis.net/downloads/microsoft/web-deploy). After that the error disappeared.

I am posting this in Oct 2019. Almost 6 years after the original post on this thread, the error still occurs, but this time on VS 2019. After looking around the web and being unable to fix it even after reinstalling Deploy 3.5/3.6 and also after updating VS, I finally managed to fix it by poking around MSBuild settings. Wanted to share it here, as this is the top search result on Google.

Steps:

Created a simple command prompt application on VS 2019. Right-clicked on the project in Solution Explorer, clicked on "Publish as Azure Webjob...", and made my Azure settings in the ensuing dialog.

Expected Result:

This simple console app would be published to Azure as a WebJob, as it always did on VS 2017.

Actual Result:

The publish operation failed with the following message:

Error : Web deployment task failed. ('Microsoft.Web.Deployment.DeploymentBaseOptions' does not contain a definition for 'UserAgent') Publish failed to deploy.

Investigation:

The error line in the Output pane in Visual Studio was pointing to the file Microsoft.Web.Publishing.targets under "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VisualStudio\v16.0\Web". Double-clicking on this error line opened up the file at a location showing the section <VSMSDeploy>. In this section, the UserAgent property was set to "$(_MSDeployUserAgent)". _MSDeployUserAgent was in turn set up under <PropertyGroup> as <_MSDeployUserAgent>VS$(_MSDeployUserAgentSource)</_MSDeployUserAgent>. The entire PropertyGroup section is pasted below for reference:

<!-- UserAgent string sent to msdeploy -->
<PropertyGroup>
    <_MSDeployUserAgentSource Condition=" '$(BuildingInsideVisualStudio)' != 'true'">$(VisualStudioVersion):CmdLine</_MSDeployUserAgentSource>
    <_MSDeployUserAgentSource Condition=" '$(BuildingInsideVisualStudio)' == 'true'">$(VisualStudioVersion):PublishDialog</_MSDeployUserAgentSource>
    <_MSDeployUserAgent>VS$(_MSDeployUserAgentSource)</_MSDeployUserAgent>
</PropertyGroup>

The Fix:

Changing UserAgent= "$(_MSDeployUserAgent)" in the <VSMSDeploy> element to UserAgent="VS$(_MSDeployUserAgentSource)" fixed the issue, and the WebJob was successfully published to my App Service.

(WARNING: Please exercise the greatest caution when modifying this file, as an incorrect change will adversely impact ALL build commands from within VS and from the command prompt.)

Concluding Observation:

After making this change to Microsoft.Web.Publishing.targets, VS seems to have proceeded with UserAgent settings akin to a CommandLine build, without distinguishing it from a PublicDialog build. All Publish-related output lines were shown in the Output pane as they used to in VS 2017, and everything went well.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!