Пример #1
0
        public IISExpressHarness(string projectPath, int serverPort, IISExpressBitness bitness = IISExpressBitness.x86, bool showWindow = false)
        {
            string fullName = new DirectoryInfo(Path.Combine(projectPath, "Web.config")).FullName;

            if (!File.Exists(fullName))
            {
                throw new Exception($"No Web.config file found in the project path directory ({fullName}).");
            }

            if (serverPort < 1 || serverPort > ushort.MaxValue)
            {
                throw new ArgumentOutOfRangeException($"The server port is invalid.");
            }

            ProjectPath = projectPath;
            ServerPort  = serverPort;
            Bitness     = bitness;
            ShowWindow  = showWindow;

            PIDUtilities.KillByPID("pid.txt", "iisexpress");
            ProcessStartInfo startInfo = CreateServerStartInfo();

            ServerProcess = StartServer(startInfo);
            PIDUtilities.StorePID("pid.txt", ServerProcess.Id);
        }
Пример #2
0
        private string GetIISExpressPath(IISExpressBitness bitness)
        {
            string folder;

            if (bitness == IISExpressBitness.x86)
            {
                folder = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
            }
            else if (bitness == IISExpressBitness.x64)
            {
                if (!Environment.Is64BitProcess)
                {
                    // SpecialFolder.ProgramFiles would still point to the x86 folder in a 32-bit process
                    folder = Environment.GetEnvironmentVariable("ProgramW6432");
                }
                else
                {
                    folder = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
                }
            }
            else
            {
                throw new ArgumentException();
            }

            string iisExpressPath = Path.Combine(folder, @"IIS Express\iisexpress.exe");

            return(iisExpressPath);
        }