Exemple #1
0
        private string GetExeFileCommandLineArguments(CodeActivityContext context)
        {
            string doNotDeleteArgument    = "-enableRule:DoNotDeleteRule";
            string computerNameArgument   = string.Format("computerName='{0}',", ComputerName.Get(context));
            string userNameArgument       = string.Format("userName='******',", Username.Get(context));
            string passwordArgument       = string.Format("password='******',", Password.Get(context));
            string webApplicationArgument = string.Format("-setParam:'IIS Web Application Name'='{0}'", IISWebApplication.Get(context));

            string msdeployArguments = (Test.Get(context) ? "-whatif" : "");

            msdeployArguments += " -source:package='{0}' -dest:auto,{1}{2}{3}authtype='Basic',includeAcls='False' -verb:sync -disableLink:AppPoolExtension -disableLink:ContentExtension -disableLink:CertificateExtension -setParamFile:\"{4}\" {5} {6} {7} {8}";

            msdeployArguments = string.Format(msdeployArguments,
                                              Path.GetFullPath(ZipPackageFilename.Get(context)),
                                              (string.IsNullOrEmpty(ComputerName.Get(context)) ? "" : computerNameArgument),
                                              (string.IsNullOrEmpty(Username.Get(context)) ? "" : userNameArgument),
                                              (string.IsNullOrEmpty(Password.Get(context)) ? "" : passwordArgument),
                                              Path.GetFullPath(ParamFilename.Get(context)),
                                              (string.IsNullOrEmpty(IISWebApplication.Get(context)) ? "" : webApplicationArgument),
                                              (DoNotDeleteFiles.Get(context) ? doNotDeleteArgument : ""),
                                              (AllowUntrustedSSLConnection.Get(context) ? "-allowUntrusted" : ""),
                                              (!string.IsNullOrEmpty(CommandLineParams.Get(context)) ? CommandLineParams.Get(context) : "")).Trim();

            return(msdeployArguments);
        }
Exemple #2
0
        private string GetCmdFileCommandLineArguments(CodeActivityContext context)
        {
            string doNotDeleteArgument    = "-enableRule:DoNotDeleteRule";
            string computerNameArgument   = string.Format("/M:{0}", ComputerName.Get(context));
            string userNameArgument       = string.Format("/U:{0}", Username.Get(context));
            string passwordArgument       = string.Format("/P:{0}", Password.Get(context));
            string webApplicationArgument = string.Format("\"-setParam:'IIS Web Application Name'='{0}'\"", IISWebApplication.Get(context));

            string msdeployArguments = (Test.Get(context) ? "/t" : "/y");

            msdeployArguments += " {0} {1} {2} {3} {4} {5} {6}";

            msdeployArguments = string.Format(msdeployArguments,
                                              (!string.IsNullOrEmpty(IISWebApplication.Get(context)) ? webApplicationArgument : ""),
                                              (DoNotDeleteFiles.Get(context) ? doNotDeleteArgument : ""),
                                              (!string.IsNullOrEmpty(ComputerName.Get(context)) ? computerNameArgument : ""),
                                              (!string.IsNullOrEmpty(Username.Get(context)) ? userNameArgument : ""),
                                              (!string.IsNullOrEmpty(Password.Get(context)) ? passwordArgument : ""),
                                              (AllowUntrustedSSLConnection.Get(context) ? "-allowUntrusted" : ""),
                                              (!string.IsNullOrEmpty(CommandLineParams.Get(context)) ? CommandLineParams.Get(context) : "")).Trim();

            return(msdeployArguments);
        }
Exemple #3
0
        protected override void Execute(CodeActivityContext context)
        {
            console = context.GetExtension <ActivityConsole>();
            if (console == null)
            {
                console = new ActivityConsole();
            }

            int version = UseVersion.Get(context);

            if (UseVersion2x.Get(context))
            {
                UseVersion.Set(context, 2);
            }

            string platformKey     = "InstallPath";
            string keyName         = string.Format(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\IIS Extensions\MSDeploy\{0}", version);
            string msdeployExePath = (string)Microsoft.Win32.Registry.GetValue(keyName, platformKey, "");

            if (string.IsNullOrEmpty(msdeployExePath))
            {
                throw new ArgumentException(string.Format("Could not find msdeploy.exe for version '{0}'.", version));
            }
            msdeployExePath = string.Format("\"{0}\"", System.IO.Path.Combine(msdeployExePath, "msdeploy.exe"));

            if (version == 2 && string.IsNullOrEmpty(Environment.GetEnvironmentVariable("MSDeployPath")))
            {
                Environment.SetEnvironmentVariable("MSDeployPath", msdeployExePath);
            }

            string executablePath;
            string arguments;

            if (ExecutionType.Get(context) == MSDeployExecutionType.Exe)
            {
                executablePath = msdeployExePath;
                arguments      = GetExeFileCommandLineArguments(context);
            }
            else
            {
                executablePath = CmdFileName.Get(context);
                arguments      = GetCmdFileCommandLineArguments(context);
            }

            string output = string.Empty;

            CommandLine commandLineHelper = new CommandLine();

            commandLineHelper.ReportProgress += new EventHandler <CommandLineProgressEventArgs>(commandLineHelper_ReportProgress);
            console.WriteLine(string.Format("{0} {1}\r\n", executablePath, arguments));
            int returnValue = commandLineHelper.Execute(executablePath, arguments, out output);

            if (output.Contains("All arguments must begin with \"-\"") && ExecutionType.Get(context) == MSDeployExecutionType.Cmd && !string.IsNullOrEmpty(IISWebApplication.Get(context)))
            {
                console.WriteLine("\n");
                console.WriteLine("**********************************************************************************************************************************************\n");
                console.WriteLine("There is a bug with 2012 versions of the .cmd files generated, which does not allow '=' to be passed on the command line.  Try the Exe method.\n");
                console.WriteLine("**********************************************************************************************************************************************\n\n");
            }

            if (output.Contains("Attempted to perform an unauthorized operation.") || output.Contains("ERROR_USER_UNAUTHORIZED") || output.Contains("ERROR_INSUFFICIENT_ACCESS_TO_SITE_FOLDER"))
            {
                console.WriteLine("\n");
                console.WriteLine("***********************************************************************************************************************\n");
                console.WriteLine("It seems the user account is not allowed to do this.  Try running as administrator or specifying username and password.\n");
                console.WriteLine("***********************************************************************************************************************\n\n");
            }

            if (output.Contains("ERROR_CERTIFICATE_VALIDATION_FAILED"))
            {
                console.WriteLine("\n");
                console.WriteLine("**********************************************************************************************************\n");
                console.WriteLine("The SSL certificate is self signed and untrusted. Tick the 'Allow Untrusted Connection' box and try again. \n");
                console.WriteLine("**********************************************************************************************************\n\n");
            }

            if (returnValue != 0 || (!output.Contains("Total changes:")))
            {
                throw new InvalidOperationException(output);
            }
        }