9
votes

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

6
Known VS2019 problem, Microsoft is largely ignoring bug reports about it. What does tend to work is posted here. - Hans Passant
Did you try as a workaround to allow untrusted certificates, as suggested by the error message? - RobertBaron
@RobertBaron all of those links are for Azure. I am not using anything Azure - MyDaftQuestions

6 Answers

13
votes

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 />
… 
… 
6
votes

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

<UseMSDeployExe>True</UseMSDeployExe>
<AllowUntrustedCertificate>True</AllowUntrustedCertificate>
2
votes

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.)

0
votes

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>
0
votes

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

0
votes

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