public void SyncTo(VSMSDeployObject destObject, /*VSMSDeploySyncOption*/ dynamic syncOptions, IVSMSDeployHost _host) { //$BUGBUG lmchen, there is only set to source provider? // set up the provider setting /*Deployment.DeploymentProviderOptions*/ dynamic srcProviderConfig = MSWebDeploymentAssembly.DynamicAssembly.CreateObject("Microsoft.Web.Deployment.DeploymentProviderOptions", new object[] { this.Provider.ToString() }); srcProviderConfig.Path = this.Root; MsDeploy.Utility.AddProviderOptions(srcProviderConfig, this.ProviderOptions, _host); using (/*Deployment.DeploymentObject*/ dynamic srcObj = MSWebDeploymentAssembly.DynamicAssembly.CallStaticMethod("Microsoft.Web.Deployment.DeploymentManager", "CreateObject", new object[] { srcProviderConfig, this.BaseOptions })) { //$BUGBUG lmchen, there is only set to source provider? // set up the parameter MsDeploy.Utility.AddSetParametersFilesToObject(srcObj, this.SetParametersFiles, _host); MsDeploy.Utility.AddSimpleSetParametersToObject(srcObj, this.Parameters, _host); MsDeploy.Utility.AddSetParametersToObject(srcObj, this.EntryParameters, _host); /*Deployment.DeploymentProviderOptions*/ dynamic destProviderConfig = MSWebDeploymentAssembly.DynamicAssembly.CreateObject("Microsoft.Web.Deployment.DeploymentProviderOptions", new object[] { destObject.Provider.ToString() }); destProviderConfig.Path = destObject.Root; // Setup Destination Provider otpion MsDeploy.Utility.AddProviderOptions(destProviderConfig, destObject.ProviderOptions, _host); srcObj.SyncTo(destProviderConfig, destObject.BaseOptions, syncOptions); } }
/// <summary> /// Sample for skipping directories // <ItemGroup> // <MsDeploySkipRules Include = "SkippingWWWRoot" > // <ObjectName>dirPath</ ObjectName > // <AbsolutePath>wwwroot</ AbsolutePath > // </MsDeploySkipRules> // </ ItemGroup > /// </summary> void IVSMSDeployHost.UpdateDeploymentBaseOptions(VSMSDeployObject srcVsMsDeployobject, VSMSDeployObject destVsMsDeployobject) { Collections.Generic.List <string> enableSkipDirectiveList = MSDeployUtility.ConvertStringIntoList(EnableSkipDirective); Collections.Generic.List <string> disableSkipDirectiveList = MSDeployUtility.ConvertStringIntoList(DisableSkipDirective); VSHostObject hostObject = new VSHostObject(HostObject as System.Collections.Generic.IEnumerable <Framework.ITaskItem>); Framework.ITaskItem[] srcSkipItems, destSkipsItems; // Add FileSkip rules from Host Object hostObject.GetFileSkips(out srcSkipItems, out destSkipsItems); Utility.AddSkipDirectiveToBaseOptions(srcVsMsDeployobject.BaseOptions, srcSkipItems, enableSkipDirectiveList, disableSkipDirectiveList, Log); Utility.AddSkipDirectiveToBaseOptions(destVsMsDeployobject.BaseOptions, destSkipsItems, enableSkipDirectiveList, disableSkipDirectiveList, Log); //Add CustomSkip Rules + AppDataSkipRules GetCustomAndAppDataSkips(out srcSkipItems, out destSkipsItems); Utility.AddSkipDirectiveToBaseOptions(srcVsMsDeployobject.BaseOptions, srcSkipItems, enableSkipDirectiveList, disableSkipDirectiveList, Log); Utility.AddSkipDirectiveToBaseOptions(destVsMsDeployobject.BaseOptions, destSkipsItems, enableSkipDirectiveList, disableSkipDirectiveList, Log); if (!string.IsNullOrEmpty(DeploymentTraceLevel)) { Diagnostics.TraceLevel deploymentTraceEventLevel = (Diagnostics.TraceLevel)System.Enum.Parse(typeof(Diagnostics.TraceLevel), DeploymentTraceLevel, true); srcVsMsDeployobject.BaseOptions.TraceLevel = deploymentTraceEventLevel; destVsMsDeployobject.BaseOptions.TraceLevel = deploymentTraceEventLevel; } Utility.AddSetParametersFilesVsMsDeployObject(srcVsMsDeployobject, ImportSetParametersItems); Utility.AddSimpleSetParametersVsMsDeployObject(srcVsMsDeployobject, SimpleSetParameterItems, OptimisticParameterDefaultValue); Utility.AddSetParametersVsMsDeployObject(srcVsMsDeployobject, SetParameterItems, OptimisticParameterDefaultValue); AddAdditionalProviderOptions(destVsMsDeployobject); }
/// <summary> /// construct /// </summary> /// <param name="src"></param> /// <param name="dest"></param> /// <param name="log"></param> internal VSMSDeployDriverInCmd(VSMSDeployObject src, VSMSDeployObject dest, IVSMSDeployHost host) : base(src, dest, host) { if (host.GetProperty("HighImportanceEventTypes") != null) { this.HighImportanceEventTypes = host.GetProperty("HighImportanceEventTypes").ToString(); } }
private void SetupPublishRelatedProperties(ref VSMSDeployObject dest) { if (AllowUntrustedCertificate) { System.Net.ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback(AllowUntrustedCertCallback); } }
public static BaseMSDeployDriver CreateBaseMSDeployDriver( VSMSDeployObject src, VSMSDeployObject dest, IVSMSDeployHost host) { BaseMSDeployDriver bmd; bmd = new VSMSDeployDriverInCmd(src, dest, host); return(bmd); }
private void AddAdditionalProviderOptions(VSMSDeployObject destVsMsDeployobject) { if (AdditionalDestinationProviderOptions != null) { foreach (ITaskItem item in AdditionalDestinationProviderOptions) { if (!string.IsNullOrEmpty(item.ItemSpec)) { string settingName = item.GetMetadata("Name"); string settingValue = item.GetMetadata("Value"); if (!string.IsNullOrEmpty(settingName) && !string.IsNullOrEmpty(settingValue)) { destVsMsDeployobject.BaseOptions.AddDefaultProviderSetting(item.ItemSpec, settingName, settingValue); } } } } }
void IVSMSDeployHost.UpdateDeploymentBaseOptions(VSMSDeployObject srcVsMsDeployobject, VSMSDeployObject destVsMsDeployobject) { Collections.Generic.List <string> enableSkipDirectiveList = MSDeployUtility.ConvertStringIntoList(EnableSkipDirective); Collections.Generic.List <string> disableSkipDirectiveList = MSDeployUtility.ConvertStringIntoList(DisableSkipDirective); MsDeploy.Utility.AddSkipDirectiveToBaseOptions(srcVsMsDeployobject.BaseOptions, null, enableSkipDirectiveList, disableSkipDirectiveList, Log); MsDeploy.Utility.AddSkipDirectiveToBaseOptions(destVsMsDeployobject.BaseOptions, null, enableSkipDirectiveList, disableSkipDirectiveList, Log); if (!string.IsNullOrEmpty(DeploymentTraceLevel)) { Diagnostics.TraceLevel deploymentTraceEventLevel = (Diagnostics.TraceLevel)System.Enum.Parse(typeof(Diagnostics.TraceLevel), DeploymentTraceLevel, true); srcVsMsDeployobject.BaseOptions.TraceLevel = deploymentTraceEventLevel; destVsMsDeployobject.BaseOptions.TraceLevel = deploymentTraceEventLevel; } MsDeploy.Utility.AddSetParametersFilesVsMsDeployObject(srcVsMsDeployobject, ImportSetParametersItems); MsDeploy.Utility.AddSimpleSetParametersVsMsDeployObject(srcVsMsDeployobject, SimpleSetParameterItems, OptimisticParameterDefaultValue); MsDeploy.Utility.AddSetParametersVsMsDeployObject(srcVsMsDeployobject, SetParameterItems, OptimisticParameterDefaultValue); AddAdditionalProviderOptions(destVsMsDeployobject); }
public override bool Execute() { Result = false; try { MsDeploy.Utility.SetupMSWebDeployDynamicAssemblies(MSDeployVersionsToTry, this); } catch (System.Exception exception) { this.Log.LogErrorFromException(exception); return(false); // failed the task } string errorMessage = null; if (!MsDeploy.Utility.CheckMSDeploymentVersion(this.Log, out errorMessage)) { return(false); } VSMSDeployObject src = null; VSMSDeployObject dest = null; if (this.Source == null || this.Source.GetLength(0) != 1) { this.Log.LogError("Source must be 1 item"); return(false); } else { src = VSMSDeployObjectFactory.CreateVSMSDeployObject(this.Source[0]); } if (this.Destination == null || this.Destination.GetLength(0) != 1) { this.Log.LogError("Destination must be 1 item"); return(false); } else { dest = VSMSDeployObjectFactory.CreateVSMSDeployObject(this.Destination[0]); VSHostObject hostObj = new VSHostObject(HostObject as System.Collections.Generic.IEnumerable <Framework.ITaskItem>); string username, password; if (hostObj.ExtractCredentials(out username, out password)) { dest.UserName = username; dest.Password = password; } } //$Todo, Should we split the Disable Link to two set of setting, one for source, one for destination src.DisableLinks = this.DisableLink; dest.DisableLinks = this.DisableLink; src.EnableLinks = this.EnableLink; dest.EnableLinks = this.EnableLink; if (this.RetryAttempts >= 0) { src.RetryAttempts = this.RetryAttempts; dest.RetryAttempts = this.RetryAttempts; } if (this.RetryInterval >= 0) { src.RetryInterval = this.RetryInterval; dest.RetryInterval = this.RetryInterval; } dest.UserAgent = this.UserAgent; SetupPublishRelatedProperties(ref dest); // change to use when we have MSDeploy implement the dispose method BaseMSDeployDriver driver = BaseMSDeployDriver.CreateBaseMSDeployDriver(src, dest, this); m_msdeployDriver = driver; try { driver.SyncThruMSDeploy(); Result = !driver.IsCancelOperation; } catch (System.Exception e) { if (e is System.Reflection.TargetInvocationException) { if (e.InnerException != null) { e = e.InnerException; } } System.Type eType = e.GetType(); if (MsDeploy.Utility.IsType(eType, MSWebDeploymentAssembly.DynamicAssembly.GetType("Microsoft.Web.Deployment.DeploymentCanceledException"))) { Log.LogMessageFromText(Resources.VSMSDEPLOY_Canceled, Microsoft.Build.Framework.MessageImportance.High); } else if (MsDeploy.Utility.IsType(eType, MSWebDelegationAssembly.DynamicAssembly.GetType("Microsoft.Web.Deployment.DeploymentException")) || MsDeploy.Utility.IsType(eType, MSWebDeploymentAssembly.DynamicAssembly.GetType("Microsoft.Web.Deployment.DeploymentFatalException"))) { MsDeploy.Utility.LogVsMsDeployException(Log, e); } else { if (!driver.IsCancelOperation) { Log.LogError(string.Format(System.Globalization.CultureInfo.CurrentCulture, Resources.VSMSDEPLOY_FailedWithException, e.Message)); } } } finally { #if NET472 if (AllowUntrustedCertificate) { System.Net.ServicePointManager.ServerCertificateValidationCallback -= new System.Net.Security.RemoteCertificateValidationCallback(AllowUntrustedCertCallback); } #endif } Utility.MsDeployEndOfExecuteMessage(Result, dest.Provider, dest.Root, Log); return(Result); }
/// <summary> /// constructor /// </summary> /// <param name="src"></param> /// <param name="dest"></param> protected BaseMSDeployDriver(VSMSDeployObject src, VSMSDeployObject dest, IVSMSDeployHost host) { _src = src; _dest = dest; _host = host; }
void IVSMSDeployHost.ClearDeploymentBaseOptions(VSMSDeployObject srcVsMsDeployobject, VSMSDeployObject destVsMsDeployobject) { // Nothing to do here }
/// <summary> /// Utility function to create DeploymentBaseOptions base on current vsMsDeployObject /// </summary> /// <param name="vSMSDeployObject"></param> /// <returns></returns> public static /*Deployment.DeploymentBaseOptions*/ dynamic CreateBaseOptions(VSMSDeployObject vSMSDeployObject) { // /*Deployment.DeploymentBaseOptions*/dynamic baseOptions = new Microsoft.Web.Deployment.DeploymentBaseOptions(); /*Deployment.DeploymentBaseOptions*/ dynamic baseOptions = MSWebDeploymentAssembly.DynamicAssembly.CreateObject("Microsoft.Web.Deployment.DeploymentBaseOptions"); if (vSMSDeployObject.IsLocal) { // do nothing } else if (!vSMSDeployObject.UseSeparatedCredential) { baseOptions.ComputerName = vSMSDeployObject.ComputerName; } else { baseOptions.ComputerName = vSMSDeployObject.ComputerName; baseOptions.UserName = vSMSDeployObject.UserName; baseOptions.Password = vSMSDeployObject.Password; } baseOptions.PrefetchPayload = vSMSDeployObject.PrefetchPayload; baseOptions.IncludeAcls = vSMSDeployObject.IncludeAcls; if (!string.IsNullOrEmpty(vSMSDeployObject.AuthenticationType)) { baseOptions.AuthenticationType = vSMSDeployObject.AuthenticationType; } if (!string.IsNullOrEmpty(vSMSDeployObject.EncryptPassword)) { baseOptions.EncryptPassword = vSMSDeployObject.EncryptPassword; } if (!string.IsNullOrEmpty(vSMSDeployObject.WebServerManifest)) { baseOptions.WebServerConfiguration.WebServerManifest = System.IO.Path.GetFileName(vSMSDeployObject.WebServerManifest); } if (!string.IsNullOrEmpty(vSMSDeployObject.WebServerDirectory)) { baseOptions.WebServerConfiguration.WebServerDirectory = vSMSDeployObject.WebServerDirectory; } if (!string.IsNullOrEmpty(vSMSDeployObject.WebServerAppHostConfigDirectory)) { baseOptions.WebServerConfiguration.ConfigurationDirectory = vSMSDeployObject.WebServerAppHostConfigDirectory; } if (vSMSDeployObject.RetryInterval >= 0) { baseOptions.RetryInterval = vSMSDeployObject.RetryInterval; } if (vSMSDeployObject.RetryAttempts >= 0) { baseOptions.RetryAttempts = vSMSDeployObject.RetryAttempts; } if (!string.IsNullOrEmpty(vSMSDeployObject.UserAgent)) { baseOptions.UserAgent = vSMSDeployObject.UserAgent; } //remove duplicate items appearing in both "EnableLinks" and "DisableLinks" caused by the default value set by publish target file Generic.List <string> enabledLinkList = ConvertStringIntoList(vSMSDeployObject.EnableLinks); Generic.List <string> disabledLinkList = ConvertStringIntoList(vSMSDeployObject.DisableLinks); foreach (string link in disabledLinkList) { if (LinkContainedInTheCollection(link, enabledLinkList)) { enabledLinkList.Remove(link); } } ChangeLinkExtensionEnableStatue(baseOptions, disabledLinkList, false); ChangeLinkExtensionEnableStatue(baseOptions, enabledLinkList, true); return(baseOptions); }
/// <summary> /// Create a simple object (no password) /// </summary> /// <param name="provider"></param> /// <param name="path"></param> /// <returns></returns> public static VSMSDeployObject CreateVSMSDeployObject(string provider, string path) { VSMSDeployObject src = new VSMSDeployObject(provider, path); return(src); }
/// <summary> /// Create a object base on msbuild task item /// </summary> /// <param name="taskItem"></param> /// <returns></returns> public static VSMSDeployObject CreateVSMSDeployObject(Build.Framework.ITaskItem taskItem) { VSMSDeployObject src = new VSMSDeployObject(taskItem); return(src); }