2016-12-02 47 views
2

我們有一個Update-Program,可以將WebDeploy-Packages自動發佈到IIS服務器。本程序適用於MVC 5 - 應用程序,但不適用於.Net核心應用程序。我們使用Microsoft.Web.Deployment - API和我publishmethod看起來是這樣的:如何將WebDeploy與ASP.Net核心一起使用

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

我沒有錯誤,但網站並沒有改變。

回答

1

是的,你可以在ASP.NET Core中使用WebDeploy。關鍵是要使用PackagePublish目標和包發佈配置:

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/

+1

不管出於什麼原因,'/噸:PackagePublish'總是與錯誤'目標「PackagePublish」返回不存在該項目'當我嘗試了。這仍然是要走的路嗎? – Scott

+0

您使用的是什麼版本的Core? – chief7

+0

看起來像1.1.1(最近安裝它,所以你可以假設最新版本)。 – Scott