如何将 WebDeploy 与 ASP.Net 核心一起使用

How to use WebDeploy with ASP.Net core

我们有一个自动发布 WebDeploy-Packages 到 IIS 服务器的更新程序。该程序适用于 MVC 5 - 应用程序,但不适用于 .Net Core 应用程序。我们使用 Microsoft.Web.Deployment - API 并且我的发布方法如下所示:

private void UpdateIIS(DTOs.ApplicationConfiguration.ApplicationServer applicationServer, DTOs.Update.Update update) {
    // SSL-Zertifikatsfehler ignorieren
    System.Net.ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback(
        (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) => { return true; });
    var sourceBaseOptions = new DeploymentBaseOptions();
    var destBaseOptions = new DeploymentBaseOptions() {
        ComputerName = string.Format("https://{0}:{1}/msdeploy.axd?site={2}", applicationServer.Adresse, applicationServer.MSDeployPort, applicationServer.SiteName),
        UserName = applicationServer.User,
        Password = applicationServer.Passwort,
        AuthenticationType = "Basic"
    };
    string updatePackage = Directory.GetFiles(update.UpdateDirectory, "*.zip").FirstOrDefault();
    if (!File.Exists(updatePackage)) {
        throw new Exception("Update-Paketdatei nicht gefunden");
    }
    using (var deploymentObject = DeploymentManager.CreateObject(
        DeploymentWellKnownProvider.Package,
        updatePackage,
        sourceBaseOptions)
    ) {
        if (deploymentObject.SyncParameters.Count > 0) {
            deploymentObject
            .SyncParameters
            .Single(p => p.Name == "IIS Web Application Name")
            .Value = applicationServer.SiteName;
        }


        var syncOptions = new DeploymentSyncOptions();
        var changes = deploymentObject.SyncTo(
            DeploymentWellKnownProvider.Auto,
            "",
            destBaseOptions,
            syncOptions
        );
    }
}

我没有收到任何错误,但网站没有改变。

是的,您可以将 Web 部署与 ASP.NET 核心一起使用。关键是使用包发布目标和包发布配置文件:

D:\GitHub\AcmeApp.NET\src\AcmeApp.NET.Web>"c:\Program Files (x86)\MSBuild.0\Bin\MSBuild" /t:PackagePublish /p:PublishProfile=Package

http://www.dotnetcatch.com/2016/09/20/webdeploy-packaging-with-asp-net-core/