private IisExpress(
            IisExpressConfiguration parameters,
            bool attachVsDebugger)
        {
            if (null == parameters)
            {
                throw new ArgumentNullException("parameters");
            }

            if (string.IsNullOrEmpty(parameters.Path))
            {
                throw new ArgumentNullException("parameters.Path");
            }

            string configFilePath = string.Format("{0}\\{1}", parameters.Path, ConfigFileName);

            File.WriteAllText(configFilePath, parameters.GetConfigFile());

            Trace.TraceInformation(
                "Starting IIS Express with configuration file: {0}",
                configFilePath);

            var executablePath = Environment.ExpandEnvironmentVariables(IssExpressLocation);

            // executing x64 bit version (unable to use Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) from x86 process)

            if (true == parameters.UseX64Process)
            {
                executablePath = executablePath.Replace(" (x86)", string.Empty);
            }

            var psi = new ProcessStartInfo
            {
                FileName  = executablePath,
                Arguments = string.Format("/{0}:\"{1}\" ", ConfigParameter, configFilePath),
                RedirectStandardOutput = true,
                UseShellExecute        = false,
            };

            foreach (var envVariable in parameters.EnvironmentVariables)
            {
                psi.EnvironmentVariables.Add(
                    envVariable.Key,
                    envVariable.Value);
            }

            this.hostProcess =
                true == attachVsDebugger
                    ? StartAndAttachVsDebugger(psi)
                    : Process.Start(psi);

            if (null == this.hostProcess)
            {
                throw new InvalidOperationException(
                          "Unable to start process",
                          new Win32Exception());
            }

            this.WaitForHostInitialization();
        }
        private IisExpress(
            IisExpressConfiguration parameters,
            bool attachVsDebugger)
        {
            if (null == parameters)
            {
                throw new ArgumentNullException("parameters");
            }

            if (string.IsNullOrEmpty(parameters.Path))
            {
                throw new ArgumentNullException("parameters.Path");
            }

            string configFilePath = string.Format("{0}\\{1}", parameters.Path, ConfigFileName);
            File.WriteAllText(configFilePath, parameters.GetConfigFile());

            Trace.TraceInformation(
                "Starting IIS Express with configuration file: {0}",
                configFilePath);

            var executablePath = Environment.ExpandEnvironmentVariables(IssExpressLocation);
            // executing x64 bit version (unable to use Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) from x86 process)

            if (true == parameters.UseX64Process)
            {
                executablePath = executablePath.Replace(" (x86)", string.Empty);
            }

            var psi = new ProcessStartInfo
                          {
                              FileName = executablePath,
                              Arguments = string.Format("/{0}:\"{1}\" ", ConfigParameter, configFilePath),
                              RedirectStandardOutput = true,
                              UseShellExecute = false,
                          };

            foreach (var envVariable in parameters.EnvironmentVariables)
            {
               psi.EnvironmentVariables.Add(
                   envVariable.Key, 
                   envVariable.Value); 
            }

            this.hostProcess = 
                true == attachVsDebugger
                    ? StartAndAttachVsDebugger(psi)
                    : Process.Start(psi);

            if (null == this.hostProcess)
            {
                throw new InvalidOperationException(
                    "Unable to start process",
                    new Win32Exception());
            }

            this.WaitForHostInitialization();
        }
 public static IisExpress Start(IisExpressConfiguration parameters,
                                bool attachVsDebugger = false)
 {
     return(new IisExpress(parameters, attachVsDebugger));
 }
 public static IisExpress Start(IisExpressConfiguration parameters,
     bool attachVsDebugger = false)
 {
     return new IisExpress(parameters, attachVsDebugger);
 }