19

I have recently uninstalled VS 2017 and installed VS 2019.

When I publish my website via Web Deploy, if fails with 2 error messages

Failed to load publish certificate dialog due to error of Object reference not set to an instance of an object. MyWebsite.Ui

Web deployment task failed. (Connected to the remote computer ("example.com") using the specified process ("Web Management Service"), but could not verify the server’s certificate. If you trust the server, connect again and allow untrusted certificates. Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_CERTIFICATE_VALIDATION_FAILED.)

I'm totally clueless on how I can solve this...

Edit

As per the comments, there is a question which is the same, but that question is about Azure. I'm not connecting to anything Azure related. I'm not saying that this makes my questions unique, more that I don't have the knowledge to understand if the cause/solution is the same. Deploying to Azure from Visual Studio fails when connecting

MyDaftQuestions
  • 4,487
  • 17
  • 63
  • 120
  • 1
    Known VS2019 problem, Microsoft is largely ignoring bug reports about it. What does tend to work is [posted here](https://stackoverflow.com/questions/15621103/deploying-to-azure-from-visual-studio-fails-when-connecting). – Hans Passant Jun 01 '19 at 13:27
  • Did you try as a workaround to allow untrusted certificates, as suggested by the error message? – RobertBaron Jun 03 '19 at 13:27
  • @RobertBaron all of those links are for Azure. I am not using anything Azure – MyDaftQuestions Jul 09 '19 at 11:41

7 Answers7

32

If you trust the server, then you can simply ignore the warning/error by editing the publish file directly

https://stackoverflow.com/a/33662970/3252861

  1. Open the publish profile file (.pubxml) inside /Properties/PublishProfiles in a text editor
  2. Inside the PropertyGroup element, set AllowUntrustedCertificate to True (AllowUntrustedCertificate> True /AllowUntrustedCertificate>) or add it if it doesn't exist
  3. Set UsePowerShell to False (False).

I didn't do the 3rd point, so I guess I either have previously or didn't need it

Now we can follow the advice on https://developercommunity.visualstudio.com/content/problem/484286/publish-fails-to-iis-using-msdeploy-webdeploy.html and actually add the following 2 entries

<UseMSDeployExe>True</UseMSDeployExe>
<AllowUntrustedCertificate>True</AllowUntrustedCertificate>

It should be pointed out that some have reported you only need to use one of those two:

<AllowUntrustedCertificate>True</AllowUntrustedCertificate>

So, the start of the pubxml XML file now looks like

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <UseMSDeployExe>True</UseMSDeployExe>
        <AllowUntrustedCertificate>True</AllowUntrustedCertificate>
        <WebPublishMethod>MSDeploy</WebPublishMethod>
        <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
        <LastUsedPlatform>Any CPU</LastUsedPlatform>
        <SiteUrlToLaunchAfterPublish />
        <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
        <ExcludeApp_Data>True</ExcludeApp_Data>
        <MSDeployServiceURL>domain</MSDeployServiceURL>
        <DeployIisAppPath>name</DeployIisAppPath>
        <RemoteSitePhysicalPath />
… 
… 
MyDaftQuestions
  • 4,487
  • 17
  • 63
  • 120
8

In your /Properties/PublishProfiles/xxxxxx.Settings.pubxml file, add the following two lines

<UseMSDeployExe>True</UseMSDeployExe>
<AllowUntrustedCertificate>True</AllowUntrustedCertificate>
John Rah
  • 1,757
  • 1
  • 14
  • 13
6

I know this is old, but I did find a different solution that worked for me (after trying to create/upload certificates; reset publishing profiles, etc.)

If you have the nuget package MSBuild.Microsoft.VisualStudio.Web.targets installed in your project, it's old and that's what breaks it. Remove that package and your publish will work. No need to add the AllowUntrusted flat in your pubxml as long as your server IS trusted. (*ie Azure.)

veevan
  • 194
  • 1
  • 6
2

I´m using VS 2019

enter image description here

enter image description here

Add the next lines into PropertyGroup node:

<UseMSDeployExe>True</UseMSDeployExe>
<AllowUntrustedCertificate>true</AllowUntrustedCertificate>

enter image description here

0

I am from the product team and I can confirm that this is the only property that needs to be set if the server certificate is untrusted.

<AllowUntrustedCertificate>True</AllowUntrustedCertificate>
vijayrkn
  • 461
  • 4
  • 7
0

Verify your code if there is any errors /C#/ Razor syntax, sometimes errors will not show in errors window.

Muni Chittem
  • 988
  • 9
  • 17
0

Same problem here. I attempted to delete the obj file folder figuring that was the problem. And it was, I had two pdf files in them that wouldn't delete being they required Admin privilege's to delete. I used the command prompt utility to go in and delete them and then did a rebuild and published with no issues.

James
  • 1
  • 1