예제 #1
0
        protected override IEnumerable <Action <XElement, string> > GetWebConfigActions()
        {
            if (IISDeploymentParameters.PublishApplicationBeforeDeployment)
            {
                // For published apps, prefer the content in the web.config, but update it.
                yield return(WebConfigHelpers.AddOrModifyAspNetCoreSection(
                                 key: "hostingModel",
                                 value: DeploymentParameters.HostingModel.ToString()));

                yield return(WebConfigHelpers.AddOrModifyHandlerSection(
                                 key: "modules",
                                 value: AspNetCoreModuleV2ModuleName));

                // We assume the x64 dotnet.exe is on the path so we need to provide an absolute path for x86 scenarios.
                // Only do it for scenarios that rely on dotnet.exe (Core, portable, etc.).
                if (DeploymentParameters.RuntimeFlavor == RuntimeFlavor.CoreClr &&
                    DeploymentParameters.ApplicationType == ApplicationType.Portable &&
                    DotNetCommands.IsRunningX86OnX64(DeploymentParameters.RuntimeArchitecture))
                {
                    var executableName = DotNetCommands.GetDotNetExecutable(DeploymentParameters.RuntimeArchitecture);
                    if (!File.Exists(executableName))
                    {
                        throw new Exception($"Unable to find '{executableName}'.'");
                    }
                    yield return(WebConfigHelpers.AddOrModifyAspNetCoreSection("processPath", executableName));
                }
            }

            foreach (var action in base.GetWebConfigActions())
            {
                yield return(action);
            }
        }
예제 #2
0
        protected override IEnumerable <Action <XElement, string> > GetWebConfigActions()
        {
            yield return(WebConfigHelpers.AddOrModifyAspNetCoreSection(
                             key: "hostingModel",
                             value: DeploymentParameters.HostingModel.ToString()));

            yield return((element, _) => {
                var aspNetCore = element
                                 .Descendants("system.webServer")
                                 .Single()
                                 .GetOrAdd("aspNetCore");

                // Expand path to dotnet because IIS process would not inherit PATH variable
                if (aspNetCore.Attribute("processPath")?.Value.StartsWith("dotnet") == true)
                {
                    aspNetCore.SetAttributeValue("processPath", DotNetCommands.GetDotNetExecutable(DeploymentParameters.RuntimeArchitecture));
                }
            });

            yield return(WebConfigHelpers.AddOrModifyHandlerSection(
                             key: "modules",
                             value: AspNetCoreModuleV2ModuleName));

            foreach (var action in base.GetWebConfigActions())
            {
                yield return(action);
            }
        }
예제 #3
0
        public override async Task <DeploymentResult> DeployAsync()
        {
            using (Logger.BeginScope("Deployment"))
            {
                StartTimer();

                var contentRoot = string.Empty;
                if (string.IsNullOrEmpty(DeploymentParameters.ServerConfigTemplateContent))
                {
                    DeploymentParameters.ServerConfigTemplateContent = File.ReadAllText("IIS.config");
                }

                _application = new IISApplication(IISDeploymentParameters, Logger);

                // For now, only support using published output
                DeploymentParameters.PublishApplicationBeforeDeployment = true;

                if (DeploymentParameters.ApplicationType == ApplicationType.Portable)
                {
                    DefaultWebConfigActions.Add(
                        WebConfigHelpers.AddOrModifyAspNetCoreSection(
                            "processPath",
                            DotNetCommands.GetDotNetExecutable(DeploymentParameters.RuntimeArchitecture)));
                }

                if (DeploymentParameters.PublishApplicationBeforeDeployment)
                {
                    DotnetPublish();
                    contentRoot = DeploymentParameters.PublishedApplicationRootPath;
                    // Do not override settings set on parameters
                    if (!IISDeploymentParameters.HandlerSettings.ContainsKey("debugLevel") &&
                        !IISDeploymentParameters.HandlerSettings.ContainsKey("debugFile"))
                    {
                        var logFile = Path.Combine(contentRoot, $"{_application.WebSiteName}.txt");
                        IISDeploymentParameters.HandlerSettings["debugLevel"] = "4";
                        IISDeploymentParameters.HandlerSettings["debugFile"]  = logFile;
                    }

                    DefaultWebConfigActions.Add(WebConfigHelpers.AddOrModifyHandlerSection(
                                                    key: "modules",
                                                    value: DeploymentParameters.AncmVersion.ToString()));
                    RunWebConfigActions(contentRoot);
                }

                var uri = TestUriHelper.BuildTestUri(ServerType.IIS, DeploymentParameters.ApplicationBaseUriHint);
                // To prevent modifying the IIS setup concurrently.
                await _application.StartIIS(uri, contentRoot);

                // Warm up time for IIS setup.
                Logger.LogInformation("Successfully finished IIS application directory setup.");
                return(new IISDeploymentResult(
                           LoggerFactory,
                           IISDeploymentParameters,
                           applicationBaseUri: uri.ToString(),
                           contentRoot: contentRoot,
                           hostShutdownToken: _hostShutdownToken.Token,
                           hostProcess: _application.HostProcess
                           ));
            }
        }
예제 #4
0
        public static void EnableLogging(this IISDeploymentParameters deploymentParameters, string path)
        {
            deploymentParameters.WebConfigActionList.Add(
                WebConfigHelpers.AddOrModifyAspNetCoreSection("stdoutLogEnabled", "true"));

            deploymentParameters.WebConfigActionList.Add(
                WebConfigHelpers.AddOrModifyAspNetCoreSection("stdoutLogFile", Path.Combine(path, "std")));
        }
예제 #5
0
        private void PrepareConfig(string contentRoot, string dllRoot, int port)
        {
            // Config is required. If not present then fall back to one we carry with us.
            if (string.IsNullOrEmpty(DeploymentParameters.ServerConfigTemplateContent))
            {
                using (var stream = GetType().Assembly.GetManifestResourceStream("Microsoft.AspNetCore.Server.IntegrationTesting.IIS.Http.config"))
                    using (var reader = new StreamReader(stream))
                    {
                        DeploymentParameters.ServerConfigTemplateContent = reader.ReadToEnd();
                    }
            }

            var serverConfig = DeploymentParameters.ServerConfigTemplateContent;

            // Pass on the applicationhost.config to iis express. With this don't need to pass in the /path /port switches as they are in the applicationHost.config
            // We take a copy of the original specified applicationHost.Config to prevent modifying the one in the repo.
            serverConfig = ModifyANCMPathInConfig(replaceFlag: "[ANCMPath]", dllName: "aspnetcore.dll", serverConfig, dllRoot);
            serverConfig = ModifyANCMPathInConfig(replaceFlag: "[ANCMV2Path]", dllName: "aspnetcorev2.dll", serverConfig, dllRoot);

            serverConfig = ReplacePlaceholder(serverConfig, "[PORT]", port.ToString(CultureInfo.InvariantCulture));
            serverConfig = ReplacePlaceholder(serverConfig, "[ApplicationPhysicalPath]", contentRoot);

            if (DeploymentParameters.PublishApplicationBeforeDeployment)
            {
                // For published apps, prefer the content in the web.config, but update it.
                DefaultWebConfigActions.Add(WebConfigHelpers.AddOrModifyAspNetCoreSection(
                                                key: "hostingModel",
                                                value: DeploymentParameters.HostingModel == HostingModel.InProcess ? "inprocess" : ""));

                DefaultWebConfigActions.Add(WebConfigHelpers.AddOrModifyHandlerSection(
                                                key: "modules",
                                                value: DeploymentParameters.AncmVersion.ToString()));
                ModifyDotNetExePathInWebConfig();
                serverConfig = RemoveRedundantElements(serverConfig);
                RunWebConfigActions();
            }
            else
            {
                // The elements normally in the web.config are in the applicationhost.config for unpublished apps.
                serverConfig = ReplacePlaceholder(serverConfig, "[HostingModel]", DeploymentParameters.HostingModel.ToString());
                serverConfig = ReplacePlaceholder(serverConfig, "[AspNetCoreModule]", DeploymentParameters.AncmVersion.ToString());
            }
            serverConfig = RunServerConfigActions(serverConfig);

            DeploymentParameters.ServerConfigLocation = Path.GetTempFileName();
            Logger.LogDebug("Saving Config to {configPath}", DeploymentParameters.ServerConfigLocation);

            File.WriteAllText(DeploymentParameters.ServerConfigLocation, serverConfig);
        }
예제 #6
0
 private void ModifyDotNetExePathInWebConfig()
 {
     // We assume the x64 dotnet.exe is on the path so we need to provide an absolute path for x86 scenarios.
     // Only do it for scenarios that rely on dotnet.exe (Core, portable, etc.).
     if (DeploymentParameters.RuntimeFlavor == RuntimeFlavor.CoreClr &&
         DeploymentParameters.ApplicationType == ApplicationType.Portable &&
         DotNetCommands.IsRunningX86OnX64(DeploymentParameters.RuntimeArchitecture))
     {
         var executableName = DotNetCommands.GetDotNetExecutable(DeploymentParameters.RuntimeArchitecture);
         if (!File.Exists(executableName))
         {
             throw new Exception($"Unable to find '{executableName}'.'");
         }
         DefaultWebConfigActions.Add(
             WebConfigHelpers.AddOrModifyAspNetCoreSection("processPath", executableName));
     }
 }
예제 #7
0
        protected override IEnumerable <Action <XElement, string> > GetWebConfigActions()
        {
            if (DeploymentParameters.ApplicationType == ApplicationType.Portable)
            {
                yield return(WebConfigHelpers.AddOrModifyAspNetCoreSection(
                                 "processPath",
                                 DotNetCommands.GetDotNetExecutable(DeploymentParameters.RuntimeArchitecture)));
            }

            yield return(WebConfigHelpers.AddOrModifyHandlerSection(
                             key: "modules",
                             value: DeploymentParameters.AncmVersion.ToString()));


            foreach (var action in base.GetWebConfigActions())
            {
                yield return(action);
            }
        }