自从使用VS 2019之后无法发布

20
我最近卸载了VS 2017并安装了VS 2019。
当我通过Web Deploy发布我的网站时,出现了两个错误信息:
“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.)”
我完全不知道该如何解决这个问题...
编辑:
根据评论中提到的一个相同的问题,但那个问题是关于Azure的。我没有连接任何与Azure相关的东西。我并不是说这使得我的问题独特,更多的是我不具备理解原因/解决方案的知识。Deploying to Azure from Visual Studio fails when connecting

1
已知的 VS2019 问题,微软在很大程度上忽视了与其有关的错误报告。能够解决该问题的方法可以在这里发布找到。 - Hans Passant
你尝试过像错误信息建议的那样允许不受信任的证书作为解决方法吗? - RobertBaron
@RobertBaron 所有这些链接都是关于 Azure 的。我没有使用任何 Azure。 - MyDaftQuestions
7个回答

33
如果您信任该服务器,则可以通过直接编辑发布文件来忽略警告/错误。{{}}

https://dev59.com/wVwX5IYBdhLWcg3wjwJZ#33662970

  1. 在文本编辑器中打开 /Properties/PublishProfiles 中的发布配置文件 (.pubxml)。
  2. 在 PropertyGroup 元素内,将 AllowUntrustedCertificate 设置为 True (AllowUntrustedCertificate> True /AllowUntrustedCertificate>) 或添加它(如果不存在)。
  3. 将 UsePowerShell 设置为 False (False)。

我没有执行第三个步骤,所以我猜我之前已经执行过或者不需要它。

现在我们可以按照https://developercommunity.visualstudio.com/content/problem/484286/publish-fails-to-iis-using-msdeploy-webdeploy.html上的建议,实际上添加以下2个条目。

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

需要指出的是,有些人报告说只需要使用这两个中的一个:

<AllowUntrustedCertificate>True</AllowUntrustedCertificate>

那么,pubxml XML文件的开头现在看起来像这样

<?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 />
… 
… 

两者都太多了并出现错误(远程提供程序关闭连接)。仅添加 <AllowUntrustedCertificate>True</AllowUntrustedCertificate> 完美解决。 - Dinand
微软 Visual Studio Community 2019 版本 16.4.5,但问题仍然存在。 - Fabio Maulo
如果你仍然遇到问题,只需确保 .pubxml 文件已包含在项目中即可。 - sandeep talabathula
有没有一种方法可以在发布配置文件中设置证书,而不是允许不受信任的主机?这样会更合理。 - SandRock

8

在您的 /Properties/PublishProfiles/xxxxxx.Settings.pubxml 文件中,添加以下两行。

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

7
我知道这是老的问题了,但我找到了一个不同的解决方案,对于我来说有效(在尝试创建/上传证书、重置发布配置文件等之后)。
如果您的项目中安装了Nuget包MSBuild.Microsoft.VisualStudio.Web.targets,它是旧的,会导致出现问题。删除该包,您的发布将正常工作。只要您的服务器受信任(如Azure),就不需要在pubxml中添加AllowUntrusted标记。

2
我正在使用VS 2019。
将以下内容添加到PropertyGroup节点中:

enter image description here

enter image description here

请在PropertyGroup节点中添加下面的行:
<UseMSDeployExe>True</UseMSDeployExe>
<AllowUntrustedCertificate>true</AllowUntrustedCertificate>

enter image description here


1
这对我有用!谢谢 - whisk

0

我也遇到了同样的问题。我试图删除obj文件夹,因为我以为那是问题所在。结果它就是问题所在,里面有两个pdf文件,由于需要管理员权限才能删除,所以无法删除。我使用命令提示工具进去删除它们,然后重新构建并发布,没有出现任何问题。


0

如果您的代码中存在错误/C# / Razor语法,请验证它,有时错误不会在错误窗口中显示。


0

我来自产品团队,我可以确认如果服务器证书不受信任,那么这是唯一需要设置的属性。

<AllowUntrustedCertificate>True</AllowUntrustedCertificate>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接