iisasp.net-coremsdeploywebdeploy

How to use WebDeploy with ASP.Net core


We have an Update-Program that publishes automatically WebDeploy-Packages to IIS-Servers. This Program works fine with MVC 5 - Applications but not with .Net Core Applications. We Use the Microsoft.Web.Deployment - API and my publish method looks like this:

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
        );
    }
}

I get no errors, but the Website doesn't change.


Solution

  • Yes you can use WebDeploy with ASP.NET Core. The key is to use the PackagePublish target and a package publish profile:

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

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