Beispiel #1
0
        /// <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);
        }
Beispiel #2
0
        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);
        }