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.