From 52802d1afa85da289dea047efe90291287d129dc Mon Sep 17 00:00:00 2001 From: Justin Kotalik Date: Wed, 2 May 2018 09:13:32 -0700 Subject: [PATCH] Make Deployers handle ANCM V1 and V2 (#1407) --- .../Common/ANCMVersion.cs | 11 +++++++++++ .../Common/DeploymentParameters.cs | 6 ++++++ .../Deployers/IISExpressDeployer.cs | 8 ++++---- 3 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Server.IntegrationTesting/Common/ANCMVersion.cs diff --git a/src/Microsoft.AspNetCore.Server.IntegrationTesting/Common/ANCMVersion.cs b/src/Microsoft.AspNetCore.Server.IntegrationTesting/Common/ANCMVersion.cs new file mode 100644 index 0000000000..5345c2dd19 --- /dev/null +++ b/src/Microsoft.AspNetCore.Server.IntegrationTesting/Common/ANCMVersion.cs @@ -0,0 +1,11 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Server.IntegrationTesting +{ + public enum ANCMVersion + { + AspNetCoreModule, + AspNetCoreModuleV2 + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.IntegrationTesting/Common/DeploymentParameters.cs b/src/Microsoft.AspNetCore.Server.IntegrationTesting/Common/DeploymentParameters.cs index bf4decf481..3cd6e3067b 100644 --- a/src/Microsoft.AspNetCore.Server.IntegrationTesting/Common/DeploymentParameters.cs +++ b/src/Microsoft.AspNetCore.Server.IntegrationTesting/Common/DeploymentParameters.cs @@ -120,6 +120,12 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting public HostingModel HostingModel { get; set; } + /// + /// When using the IISExpressDeployer, determines whether to use the older or newer version + /// of ANCM. + /// + public ANCMVersion ANCMVersion { get; set; } = ANCMVersion.AspNetCoreModule; + /// /// Environment variables to be set before starting the host. /// Not applicable for IIS Scenarios. diff --git a/src/Microsoft.AspNetCore.Server.IntegrationTesting/Deployers/IISExpressDeployer.cs b/src/Microsoft.AspNetCore.Server.IntegrationTesting/Deployers/IISExpressDeployer.cs index 286e05859d..cc27f9d6c4 100644 --- a/src/Microsoft.AspNetCore.Server.IntegrationTesting/Deployers/IISExpressDeployer.cs +++ b/src/Microsoft.AspNetCore.Server.IntegrationTesting/Deployers/IISExpressDeployer.cs @@ -106,7 +106,6 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting // 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. - if (serverConfig.Contains("[ANCMPath]")) { // We need to pick the bitness based the OS / IIS Express, not the application. @@ -166,8 +165,9 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting if (DeploymentParameters.HostingModel == HostingModel.InProcess) { - ModifyWebConfigToInProcess(); + ModifyAspNetCoreSectionInWebConfig(key: "hostingModel", value: "inprocess"); } + ModifyAspNetCoreSectionInWebConfig(key: "modules", value: DeploymentParameters.ANCMVersion.ToString()); var parameters = string.IsNullOrWhiteSpace(DeploymentParameters.ServerConfigLocation) ? string.Format("/port:{0} /path:\"{1}\" /trace:error", uri.Port, contentRoot) : @@ -319,12 +319,12 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting // Transforms the web.config file to include the hostingModel="inprocess" element // and adds the server type = Microsoft.AspNetServer.IIS such that Kestrel isn't added again in ServerTests - private void ModifyWebConfigToInProcess() + private void ModifyAspNetCoreSectionInWebConfig(string key, string value) { var webConfigFile = $"{DeploymentParameters.PublishedApplicationRootPath}/web.config"; var config = XDocument.Load(webConfigFile); var element = config.Descendants("aspNetCore").FirstOrDefault(); - element.SetAttributeValue("hostingModel", "inprocess"); + element.SetAttributeValue(key, value); config.Save(webConfigFile); } }