Publishing from Visual Studio 2015 - allow untrusted certificates
I am publishing my ASP.NET 5 MVC6 project from Visual Studio 2015. I have imported publish profile from my server. Connection validates successfully, however when I publish my project I have the following error:
ERROR_CERTIFICATE_VALIDATION_FAILED
Connected to the remote computer ("XXXXXXXXX") 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.
There is no option to allow untrusted certificates in publishing settings.
Solution 1:
The option to allow untrusted certificates is not yet supported in the current tooling. Hopefully, this gets updated very soon. You can, however, set it manually.
- Open the publish profile file (
.pubxml
) inside /Properties/PublishProfiles in a text editor - Inside the
<PropertyGroup>
element, set AllowUntrustedCertificate to True (<AllowUntrustedCertificate>True</AllowUntrustedCertificate>
) or add it if it doesn't exist - Set UsePowerShell to False (
<UsePowerShell>False</UsePowerShell>
).
At this time of writing, the generated powershell script disregards the AllowUntrustedCertificate
property which is probably a bug, hence, the need to set it to False
.
You can get powershell to work if you update the module version in the .ps1
file.
As a side note, you can also get around this problem by "trusting" the server's certificate locally.
Solution 2:
For dot net core 1.0 you have to add the tag
<AllowUntrustedCertificate>True</AllowUntrustedCertificate>
to publishprofiles in your .pubxml file
Solution 3:
For me, the solution took 4 lines in the publish profile xml.
<AllowUntrustedCertificate>True</AllowUntrustedCertificate>
<UseMsDeployExe>true</UseMsDeployExe>
<UserName>myuser</UserName>
<Password>mypass</Password>
The UseMsDeployExe
changes the error to ignore the certificate, but not authenticate the user, hence the need for the user and pass (of the machine you're deploying to)
No changes were needed in the powershell script.
Solution 4:
I had <UsePowerShell>True</UsePowerShell>
but it was still failing with the cert error.
- I re-entered my password in the settings dialog and it still failed
- Once I clicked on Validate Connection it started working.
Note
- VS 2017 (15.2)
- My password recently changed
- As a test, entered the wrong password and I got the cert error so the cert error is not just about an untrusted cert apparently