迁移到 VS 2019 后无法发布

Can not publish since moving to VS 2019

我最近卸载了 VS 2017 并安装了 VS 2019。

当我通过 Web 部署发布我的网站时,如果失败并显示 2 条错误消息

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 相关的东西。我并不是说这让我的问题变得独特,更多的是我不知道 cause/solution 是否相同。 Deploying to Azure from Visual Studio fails when connecting

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

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

如果您信任服务器,那么您可以通过直接编辑发布文件

来忽略warning/error

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

第三点我没有做,所以我想我以前有过或者不需要

现在我们可以按照 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>

验证你的代码是否有任何错误 /C#/ Razor 语法,有时错误不会在错误中显示 window。

我知道这是旧的,但我确实找到了适合我的不同解决方案(在尝试 create/upload 证书后;重置发布配置文件等)

如果您的项目中安装了 nuget 包 MSBuild.Microsoft.VisualStudio.Web.targets,它就太旧了,这就是它的问题所在。删除该包,您的发布将起作用。只要您的服务器是可信的,就无需在您的 pubxml 中添加 AllowUntrusted 平面。 (*即 Azure。)

我正在使用 VS 2019

将下一行添加到 PropertyGroup 节点中:

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