private static void Deploy( string sourcePath, string destinationPath, string destinationAddress, string userName, string password, DeploymentWellKnownProvider srcProvider, DeploymentBaseOptions srcBaseOptions, DeploymentWellKnownProvider destProvider, DeploymentBaseOptions destBaseOptions, DeploymentSyncOptions destSyncOptions, Func <string, string> syncParamResolver, IEnumerable <DeploymentSkipDirective> skipDirectives = null, IEnumerable <string> removedParameters = null, TraceLevel tracelevel = TraceLevel.Info, WebDeploySyncDirection direction = (WebDeploySyncDirection.SourceIsLocal | WebDeploySyncDirection.DestinationIsRemote)) { ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, e) => true; // prepare common source properties srcBaseOptions.Trace += DeployTraceEventHandler; srcBaseOptions.TraceLevel = tracelevel; if (direction.HasFlag(WebDeploySyncDirection.SourceIsRemote)) { srcBaseOptions.ComputerName = destinationAddress; srcBaseOptions.UserName = userName; srcBaseOptions.Password = password; srcBaseOptions.AuthenticationType = "basic"; } // prepare common destination properties destBaseOptions.Trace += DeployTraceEventHandler; destBaseOptions.TraceLevel = tracelevel; destBaseOptions.IncludeAcls = true; // We want to ignore errors to delete files because this is what WebMatrix does. This may result in a partial deployment destBaseOptions.AddDefaultProviderSetting(DeploymentWellKnownProvider.FilePath.ToString(), "ignoreErrors", "0x80070005;0x80070020;0x80070091"); destBaseOptions.AddDefaultProviderSetting(DeploymentWellKnownProvider.DirPath.ToString(), "ignoreErrors", "0x80070005;0x80070020;0x80070091"); if (direction.HasFlag(WebDeploySyncDirection.DestinationIsRemote)) { destBaseOptions.ComputerName = destinationAddress; destBaseOptions.UserName = userName; destBaseOptions.Password = password; destBaseOptions.AuthenticationType = "basic"; } if (skipDirectives != null) { foreach (var skipDirective in skipDirectives) { srcBaseOptions.SkipDirectives.Add(skipDirective); destBaseOptions.SkipDirectives.Add(skipDirective); } } ExecuteDeploy(sourcePath, destinationPath, srcProvider, srcBaseOptions, destProvider, destBaseOptions, destSyncOptions, syncParamResolver, removedParameters); }
private static void ExecuteDeploy( string sourcePath, string destinationPath, DeploymentWellKnownProvider srcProvider, DeploymentBaseOptions srcBaseOptions, DeploymentWellKnownProvider destProvider, DeploymentBaseOptions destBaseOptions, DeploymentSyncOptions destSyncOptions, Func <string, string> syncParamResolver = null, IEnumerable <string> removedParameters = null) { ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, e) => true; try { using (DeploymentObject deployObj = DeploymentManager.CreateObject(srcProvider, sourcePath, srcBaseOptions)) { // resolve parameters if any if (syncParamResolver != null) { foreach (var syncParam in deployObj.SyncParameters) { var resolvedValue = syncParamResolver(syncParam.Name); if (resolvedValue != null) { syncParam.Value = resolvedValue; } } } // remove parameters if any if (removedParameters != null) { foreach (var parameter in removedParameters) { deployObj.SyncParameters.Remove(parameter); } } TestEasyLog.Instance.Info(string.Format("Deploying: {0}", sourcePath)); // do action TestEasyLog.Instance.LogObject(deployObj.SyncTo(destProvider, destinationPath, destBaseOptions, destSyncOptions)); } } catch (Exception e) { TestEasyLog.Instance.Info(string.Format("Exception during deployment of '{0}': '{1}'", sourcePath, e.Message)); throw; } }
/// <summary> /// Deploy package from different sources to different destiations using WebDeploy /// </summary> /// <param name="sourcePath"></param> /// <param name="destinationPath"></param> /// <param name="destinationAddress"></param> /// <param name="user"></param> /// <param name="password"></param> /// <param name="deleteExisting"></param> /// <param name="paramResolverFunc"></param> public static void DeployPackage( string sourcePath, string destinationPath, string destinationAddress, string user, string password, bool deleteExisting = true, Func <string, string> paramResolverFunc = null) { InitializeWebDeployment(); var skipDirectives = new List <DeploymentSkipDirective> { new DeploymentSkipDirective("skipDbFullSql", @"objectName=dbFullSql", true), new DeploymentSkipDirective("skipDbMySql", @"objectName=dbMySql", true) }; // define a source deployment provider and its properties const DeploymentWellKnownProvider srcProvider = DeploymentWellKnownProvider.Package; var srcBaseOptions = new DeploymentBaseOptions(); // define a destination deployment provider and its properties const DeploymentWellKnownProvider destProvider = DeploymentWellKnownProvider.Auto; var destBaseOptions = new DeploymentBaseOptions(); // define a synchronization options and set if we shoudl delete existing files var destSyncOptions = new DeploymentSyncOptions { DoNotDelete = !deleteExisting }; Deploy( sourcePath, destinationPath, destinationAddress, user, password, srcProvider, srcBaseOptions, destProvider, destBaseOptions, destSyncOptions, paramResolverFunc, skipDirectives.AsEnumerable()); }
private static void PrepareDatabaseDeployment(WebDeployDatabaseType dbType, out DeploymentWellKnownProvider provider, out DeploymentBaseOptions options, bool includeData = false, bool dropDestinationDatabase = false) { provider = DeploymentWellKnownProvider.DBDacFx; options = new DeploymentBaseOptions(); switch (dbType) { case WebDeployDatabaseType.SqlCe: case WebDeployDatabaseType.FullSql: provider = DeploymentWellKnownProvider.DBDacFx; break; case WebDeployDatabaseType.MySql: provider = DeploymentWellKnownProvider.DBMySql; break; } options.AddDefaultProviderSetting(provider.ToString(), "dropDestinationDatabase", dropDestinationDatabase); options.AddDefaultProviderSetting(provider.ToString(), "includeData", includeData); }
/// <summary> /// Deploy directory from different sources to different destiations using WebDeploy /// </summary> /// <param name="sourcePath"></param> /// <param name="destinationPath"></param> /// <param name="destinationAddress"></param> /// <param name="user"></param> /// <param name="password"></param> /// <param name="deleteExisting"></param> /// <param name="paramResolverFunc"></param> public static void DeployDirectory( string sourcePath, string destinationPath, string destinationAddress, string user, string password, bool deleteExisting = true, Func <string, string> paramResolverFunc = null) { InitializeWebDeployment(); // define a source deployment provider and its properties const DeploymentWellKnownProvider srcProvider = DeploymentWellKnownProvider.ContentPath; var srcBaseOptions = new DeploymentBaseOptions(); // define a destination deployment provider and its properties const DeploymentWellKnownProvider destProvider = DeploymentWellKnownProvider.ContentPath; var destBaseOptions = new DeploymentBaseOptions(); // define a synchronization options and set if we shoudl delete existing files var destSyncOptions = new DeploymentSyncOptions { DoNotDelete = !deleteExisting }; Deploy( sourcePath, destinationPath, destinationAddress, user, password, srcProvider, srcBaseOptions, destProvider, destBaseOptions, destSyncOptions, paramResolverFunc); }
private static void ExecuteDeploy( string sourcePath, string destinationPath, DeploymentWellKnownProvider srcProvider, DeploymentBaseOptions srcBaseOptions, DeploymentWellKnownProvider destProvider, DeploymentBaseOptions destBaseOptions, DeploymentSyncOptions destSyncOptions, Func<string, string> syncParamResolver = null, IEnumerable<string> removedParameters = null) { ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, e) => true; try { using (DeploymentObject deployObj = DeploymentManager.CreateObject(srcProvider, sourcePath, srcBaseOptions)) { // resolve parameters if any if (syncParamResolver != null) { foreach (var syncParam in deployObj.SyncParameters) { var resolvedValue = syncParamResolver(syncParam.Name); if (resolvedValue != null) { syncParam.Value = resolvedValue; } } } // remove parameters if any if (removedParameters != null) { foreach (var parameter in removedParameters) { deployObj.SyncParameters.Remove(parameter); } } TestEasyLog.Instance.Info(string.Format("Deploying: {0}", sourcePath)); // do action TestEasyLog.Instance.LogObject(deployObj.SyncTo(destProvider, destinationPath, destBaseOptions, destSyncOptions)); } } catch (Exception e) { TestEasyLog.Instance.Info(string.Format("Exception during deployment of '{0}': '{1}'", sourcePath, e.Message)); throw; } }
private static void Deploy( string sourcePath, string destinationPath, string destinationAddress, string userName, string password, DeploymentWellKnownProvider srcProvider, DeploymentBaseOptions srcBaseOptions, DeploymentWellKnownProvider destProvider, DeploymentBaseOptions destBaseOptions, DeploymentSyncOptions destSyncOptions, Func<string, string> syncParamResolver, IEnumerable<DeploymentSkipDirective> skipDirectives = null, IEnumerable<string> removedParameters = null, TraceLevel tracelevel = TraceLevel.Info, WebDeploySyncDirection direction = (WebDeploySyncDirection.SourceIsLocal | WebDeploySyncDirection.DestinationIsRemote)) { ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, e) => true; // prepare common source properties srcBaseOptions.Trace += DeployTraceEventHandler; srcBaseOptions.TraceLevel = tracelevel; if (direction.HasFlag(WebDeploySyncDirection.SourceIsRemote)) { srcBaseOptions.ComputerName = destinationAddress; srcBaseOptions.UserName = userName; srcBaseOptions.Password = password; srcBaseOptions.AuthenticationType = "basic"; } // prepare common destination properties destBaseOptions.Trace += DeployTraceEventHandler; destBaseOptions.TraceLevel = tracelevel; destBaseOptions.IncludeAcls = true; // We want to ignore errors to delete files because this is what WebMatrix does. This may result in a partial deployment destBaseOptions.AddDefaultProviderSetting(DeploymentWellKnownProvider.FilePath.ToString(), "ignoreErrors", "0x80070005;0x80070020;0x80070091"); destBaseOptions.AddDefaultProviderSetting(DeploymentWellKnownProvider.DirPath.ToString(), "ignoreErrors", "0x80070005;0x80070020;0x80070091"); if (direction.HasFlag(WebDeploySyncDirection.DestinationIsRemote)) { destBaseOptions.ComputerName = destinationAddress; destBaseOptions.UserName = userName; destBaseOptions.Password = password; destBaseOptions.AuthenticationType = "basic"; } if (skipDirectives != null) { foreach (var skipDirective in skipDirectives) { srcBaseOptions.SkipDirectives.Add(skipDirective); destBaseOptions.SkipDirectives.Add(skipDirective); } } ExecuteDeploy(sourcePath, destinationPath, srcProvider, srcBaseOptions, destProvider, destBaseOptions, destSyncOptions, syncParamResolver, removedParameters); }
/// <summary> /// Deploys the content of a website /// </summary> /// <param name="settings">The deployment settings.</param> /// <returns>The <see cref="DeploymentChangeSummary"/> that was applied during the deployment.</returns> public DeploymentChangeSummary Deploy(DeploySettings settings) { if (settings == null) { throw new ArgumentNullException("settings"); } if (settings.SourcePath == null) { throw new ArgumentNullException("settings.SourcePath"); } DeploymentBaseOptions sourceOptions = new DeploymentBaseOptions(); DeploymentBaseOptions destOptions = this.GetBaseOptions(settings); FilePath sourcePath = settings.SourcePath.MakeAbsolute(_Environment); string destPath = settings.SiteName; destOptions.TraceLevel = settings.TraceLevel; destOptions.Trace += OnTraceEvent; DeploymentWellKnownProvider sourceProvider = DeploymentWellKnownProvider.ContentPath; DeploymentWellKnownProvider destProvider = DeploymentWellKnownProvider.Auto; //If a target path was specified, it could be virtual or physical if (settings.DestinationPath != null) { if (System.IO.Path.IsPathRooted(settings.DestinationPath.FullPath)) { // If it's rooted (e.g. d:\home\site\foo), use DirPath sourceProvider = DeploymentWellKnownProvider.DirPath; destProvider = DeploymentWellKnownProvider.DirPath; destPath = settings.DestinationPath.FullPath; } else { // It's virtual, so append it to what we got from the publish profile destPath += "/" + settings.DestinationPath.FullPath; } } //When a SiteName is given but no DestinationPath else if (!String.IsNullOrWhiteSpace(settings.SiteName)) { //use ContentPath so it gets deployed to the Path of the named website in IIS //which is the same behaviour as in Visual Studio destProvider = DeploymentWellKnownProvider.ContentPath; } //If the content path is a zip file, use the Package provider string extension = sourcePath.GetExtension(); if (extension != null && extension.Equals(".zip", StringComparison.OrdinalIgnoreCase)) { // For some reason, we can't combine a zip with a physical target path if (destProvider == DeploymentWellKnownProvider.DirPath) { throw new Exception("A source zip file can't be used with a physical target path"); } sourceProvider = DeploymentWellKnownProvider.Package; } //Sync Options DeploymentSyncOptions syncOptions = new DeploymentSyncOptions { DoNotDelete = !settings.Delete, WhatIf = settings.WhatIf }; // Add SkipRules foreach (var rule in settings.SkipRules) { syncOptions.Rules.Add(new DeploymentSkipRule(rule.Name, rule.SkipAction, rule.ObjectName, rule.AbsolutePath, rule.XPath)); } //Deploy _Log.Debug(Verbosity.Normal, "Deploying Website..."); _Log.Debug(Verbosity.Normal, String.Format("-siteName '{0}'", settings.SiteName)); _Log.Debug(Verbosity.Normal, String.Format("-destination '{0}'", settings.PublishUrl)); _Log.Debug(Verbosity.Normal, String.Format("-source '{0}'", sourcePath.FullPath)); _Log.Debug(""); using (var deploymentObject = DeploymentManager.CreateObject(sourceProvider, sourcePath.FullPath, sourceOptions)) { foreach (var kv in settings.Parameters) { if (deploymentObject.SyncParameters.Contains(kv.Key)) { deploymentObject.SyncParameters[kv.Key].Value = kv.Value; } else { deploymentObject.SyncParameters.Add(new DeploymentSyncParameter(kv.Key, kv.Key, "", "") { Value = kv.Value }); } } return(deploymentObject.SyncTo(destProvider, destPath, destOptions, syncOptions)); } }