From 54bc8022afad91952f21cd9e69e334b97b49fbc0 Mon Sep 17 00:00:00 2001 From: moozzyk Date: Fri, 11 Mar 2016 10:03:14 -0800 Subject: [PATCH] Moving publish-iis from httpPlatformHandler to aspNetCoreModule --- .../Program.cs | 4 +- .../WebConfigTransform.cs | 52 +++++++++--------- .../project.json | 3 +- .../PublishIISCommandFacts.cs | 22 ++++---- .../WebConfigTransformFacts.cs | 54 +++++++++---------- .../project.json | 2 +- 6 files changed, 69 insertions(+), 68 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.IISIntegration.Tools/Program.cs b/src/Microsoft.AspNetCore.Server.IISIntegration.Tools/Program.cs index c279b3bb7b..cd1b7153a2 100644 --- a/src/Microsoft.AspNetCore.Server.IISIntegration.Tools/Program.cs +++ b/src/Microsoft.AspNetCore.Server.IISIntegration.Tools/Program.cs @@ -5,9 +5,9 @@ using System; using Microsoft.DotNet.Cli.Utils; using Microsoft.Extensions.CommandLineUtils; -namespace Microsoft.AspNetCore.Tools.PublishIIS +namespace Microsoft.AspNetCore.Server.IISIntegration.Tools { - public class Microsoft.AspNetCore.Server.IISIntegration.Tools + public class Program { public static int Main(string[] args) { diff --git a/src/Microsoft.AspNetCore.Server.IISIntegration.Tools/WebConfigTransform.cs b/src/Microsoft.AspNetCore.Server.IISIntegration.Tools/WebConfigTransform.cs index 2d6a0994f3..0d62724194 100644 --- a/src/Microsoft.AspNetCore.Server.IISIntegration.Tools/WebConfigTransform.cs +++ b/src/Microsoft.AspNetCore.Server.IISIntegration.Tools/WebConfigTransform.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools public static XDocument Transform(XDocument webConfig, string appName, bool configureForAzure) { const string HandlersElementName = "handlers"; - const string httpPlatformElementName = "httpPlatform"; + const string aspNetCoreElementName = "aspNetCore"; webConfig = webConfig == null || webConfig.Root.Name.LocalName != "configuration" ? XDocument.Parse("") @@ -22,15 +22,15 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools var webServerSection = GetOrCreateChild(webConfig.Root, "system.webServer"); TransformHandlers(GetOrCreateChild(webServerSection, HandlersElementName)); - TransformHttpPlatform(GetOrCreateChild(webServerSection, httpPlatformElementName), appName, configureForAzure); + TransformAspNetCore(GetOrCreateChild(webServerSection, aspNetCoreElementName), appName, configureForAzure); - // make sure that the httpPlatform element is after handlers element - var httpPlatformElement = webServerSection.Element(HandlersElementName) - .ElementsBeforeSelf(httpPlatformElementName).SingleOrDefault(); - if (httpPlatformElement != null) + // make sure that the aspNetCore element is after handlers element + var aspNetCoreElement = webServerSection.Element(HandlersElementName) + .ElementsBeforeSelf(aspNetCoreElementName).SingleOrDefault(); + if (aspNetCoreElement != null) { - httpPlatformElement.Remove(); - webServerSection.Element(HandlersElementName).AddAfterSelf(httpPlatformElement); + aspNetCoreElement.Remove(); + webServerSection.Element(HandlersElementName).AddAfterSelf(aspNetCoreElement); } return webConfig; @@ -38,41 +38,41 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools private static void TransformHandlers(XElement handlersElement) { - var platformHandlerElement = + var aspNetCoreElement = handlersElement.Elements("add") - .FirstOrDefault(e => string.Equals((string)e.Attribute("name"), "httpplatformhandler", StringComparison.OrdinalIgnoreCase)); + .FirstOrDefault(e => string.Equals((string)e.Attribute("name"), "aspnetcore", StringComparison.OrdinalIgnoreCase)); - if (platformHandlerElement == null) + if (aspNetCoreElement == null) { - platformHandlerElement = new XElement("add"); - handlersElement.Add(platformHandlerElement); + aspNetCoreElement = new XElement("add"); + handlersElement.Add(aspNetCoreElement); } - platformHandlerElement.SetAttributeValue("name", "httpPlatformHandler"); - SetAttributeValueIfEmpty(platformHandlerElement, "path", "*"); - SetAttributeValueIfEmpty(platformHandlerElement, "verb", "*"); - SetAttributeValueIfEmpty(platformHandlerElement, "modules", "httpPlatformHandler"); - SetAttributeValueIfEmpty(platformHandlerElement, "resourceType", "Unspecified"); + aspNetCoreElement.SetAttributeValue("name", "aspNetCore"); + SetAttributeValueIfEmpty(aspNetCoreElement, "path", "*"); + SetAttributeValueIfEmpty(aspNetCoreElement, "verb", "*"); + SetAttributeValueIfEmpty(aspNetCoreElement, "modules", "AspNetCoreModule"); + SetAttributeValueIfEmpty(aspNetCoreElement, "resourceType", "Unspecified"); } - private static void TransformHttpPlatform(XElement httpPlatformElement, string appName, bool configureForAzure) + private static void TransformAspNetCore(XElement aspNetCoreElement, string appName, bool configureForAzure) { var appPath = Path.Combine(configureForAzure ? @"%home%\site" : "..", appName); var logPath = Path.Combine(configureForAzure ? @"\\?\%home%\LogFiles" : @"..\logs", "stdout.log"); - httpPlatformElement.SetAttributeValue("processPath", appPath); - SetAttributeValueIfEmpty(httpPlatformElement, "stdoutLogEnabled", "false"); - SetAttributeValueIfEmpty(httpPlatformElement, "stdoutLogFile", logPath); - SetAttributeValueIfEmpty(httpPlatformElement, "startupTimeLimit", "3600"); + aspNetCoreElement.SetAttributeValue("processPath", appPath); + SetAttributeValueIfEmpty(aspNetCoreElement, "stdoutLogEnabled", "false"); + SetAttributeValueIfEmpty(aspNetCoreElement, "stdoutLogFile", logPath); + SetAttributeValueIfEmpty(aspNetCoreElement, "startupTimeLimit", "3600"); - AddApplicationBase(httpPlatformElement); + AddApplicationBase(aspNetCoreElement); } - private static void AddApplicationBase(XElement httpPlatformElement) + private static void AddApplicationBase(XElement aspNetCoreElement) { const string appBaseKeyName = "ASPNET_APPLICATIONBASE"; - var envVariables = GetOrCreateChild(httpPlatformElement, "environmentVariables"); + var envVariables = GetOrCreateChild(aspNetCoreElement, "environmentVariables"); var appBaseElement = envVariables.Elements("environmentVariable").SingleOrDefault(e => string.Equals((string)e.Attribute("name"), appBaseKeyName, StringComparison.CurrentCultureIgnoreCase)); diff --git a/src/Microsoft.AspNetCore.Server.IISIntegration.Tools/project.json b/src/Microsoft.AspNetCore.Server.IISIntegration.Tools/project.json index 130896ffb0..9087a880cd 100644 --- a/src/Microsoft.AspNetCore.Server.IISIntegration.Tools/project.json +++ b/src/Microsoft.AspNetCore.Server.IISIntegration.Tools/project.json @@ -5,7 +5,8 @@ "warningsAsErrors": true, "keyFile": "../../tools/Key.snk", "nowarn": [ "CS1591" ], - "xmlDoc": true + "xmlDoc": true, + "outputName": "dotnet-publish-iis" }, "dependencies": { diff --git a/test/Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests/PublishIISCommandFacts.cs b/test/Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests/PublishIISCommandFacts.cs index 5c00ae007d..b22aa68b52 100644 --- a/test/Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests/PublishIISCommandFacts.cs +++ b/test/Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests/PublishIISCommandFacts.cs @@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests new PublishIISCommand(folders.PublishOutput, folders.ProjectPath, null).Run(); var processPath = (string)GetPublishedWebConfig(folders.PublishOutput, webRoot) - .Descendants("httpPlatform").Attributes("processPath").Single(); + .Descendants("aspNetCore").Attributes("processPath").Single(); Assert.Equal($@"..\projectDir.exe", processPath); @@ -42,7 +42,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests new PublishIISCommand(folders.PublishOutput, folders.ProjectPath, null).Run(); var processPath = (string)GetPublishedWebConfig(folders.PublishOutput, webRoot) - .Descendants("httpPlatform").Attributes("processPath").Single(); + .Descendants("aspNetCore").Attributes("processPath").Single(); Assert.Equal($@"..\{projectName}.exe", processPath); @@ -59,7 +59,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests new PublishIISCommand(folders.PublishOutput, folders.ProjectPath, null).Run(); var processPath = (string)GetPublishedWebConfig(folders.PublishOutput, webRoot) - .Descendants("httpPlatform").Attributes("processPath").Single(); + .Descendants("aspNetCore").Attributes("processPath").Single(); Assert.Equal(@"..\projectDir.exe", processPath); @@ -76,7 +76,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests new PublishIISCommand(folders.PublishOutput, folders.ProjectPath, webRoot).Run(); var processPath = (string)GetPublishedWebConfig(folders.PublishOutput, webRoot) - .Descendants("httpPlatform").Attributes("processPath").Single(); + .Descendants("aspNetCore").Attributes("processPath").Single(); Assert.Equal(@"..\projectDir.exe", processPath); @@ -94,7 +94,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests new PublishIISCommand(folders.PublishOutput, Path.Combine(folders.ProjectPath, "project.json"), null).Run(); var processPath = (string)GetPublishedWebConfig(folders.PublishOutput, webRoot) - .Descendants("httpPlatform").Attributes("processPath").Single(); + .Descendants("aspNetCore").Attributes("processPath").Single(); Assert.Equal($@"..\{projectDir}.exe", processPath); @@ -111,19 +111,19 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests @" - + - + "); new PublishIISCommand(folders.PublishOutput, Path.Combine(folders.ProjectPath, "project.json"), null).Run(); - var httpPlatformElement = GetPublishedWebConfig(folders.PublishOutput, webRoot) - .Descendants("httpPlatform").Single(); + var aspNetCoreElement = GetPublishedWebConfig(folders.PublishOutput, webRoot) + .Descendants("aspNetCore").Single(); - Assert.Equal(@"..\projectDir.exe", (string)httpPlatformElement.Attribute("processPath")); - Assert.Equal(@"1234", (string)httpPlatformElement.Attribute("startupTimeLimit")); + Assert.Equal(@"..\projectDir.exe", (string)aspNetCoreElement.Attribute("processPath")); + Assert.Equal(@"1234", (string)aspNetCoreElement.Attribute("startupTimeLimit")); Directory.Delete(folders.TestRoot, recursive: true); } diff --git a/test/Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests/WebConfigTransformFacts.cs b/test/Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests/WebConfigTransformFacts.cs index 8c5cdee79c..b21aaf340e 100644 --- a/test/Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests/WebConfigTransformFacts.cs +++ b/test/Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests/WebConfigTransformFacts.cs @@ -10,13 +10,13 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests @" - + - + - + "); @@ -38,10 +38,10 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests [InlineData(new object[] { new[] { "system.webServer" } })] [InlineData(new object[] { new[] { "add" } })] [InlineData(new object[] { new[] { "handlers" } })] - [InlineData(new object[] { new[] { "httpPlatform" } })] + [InlineData(new object[] { new[] { "aspNetCore" } })] [InlineData(new object[] { new[] { "environmentVariables" } })] [InlineData(new object[] { new[] { "environmentVariable" } })] - [InlineData(new object[] { new[] { "handlers", "httpPlatform", "environmentVariables" } })] + [InlineData(new object[] { new[] { "handlers", "aspNetCore", "environmentVariables" } })] public void WebConfigTransform_adds_missing_elements(string[] elementNames) { var input = WebConfigTemplate; @@ -59,10 +59,10 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests [InlineData("add", "verb", "test")] [InlineData("add", "modules", "mods")] [InlineData("add", "resourceType", "Either")] - [InlineData("httpPlatform", "stdoutLogEnabled", "true")] - [InlineData("httpPlatform", "startupTimeLimit", "1200")] - [InlineData("httpPlatform", "arguments", "arg1")] - [InlineData("httpPlatform", "stdoutLogFile", "logfile.log")] + [InlineData("aspNetCore", "stdoutLogEnabled", "true")] + [InlineData("aspNetCore", "startupTimeLimit", "1200")] + [InlineData("aspNetCore", "arguments", "arg1")] + [InlineData("aspNetCore", "stdoutLogFile", "logfile.log")] public void WebConfigTransform_wont_override_custom_values(string elementName, string attributeName, string attributeValue) { var input = WebConfigTemplate; @@ -77,23 +77,23 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests { var newProcessPath = (string)WebConfigTransform.Transform(WebConfigTemplate, "app.exe", configureForAzure: false) - .Descendants("httpPlatform").Single().Attribute("processPath"); + .Descendants("aspNetCore").Single().Attribute("processPath"); Assert.Equal(@"..\app.exe", newProcessPath); } [Fact] - public void WebConfigTransform_fixes_httpPlatformHandler_casing() + public void WebConfigTransform_fixes_aspnetcore_casing() { var input = WebConfigTemplate; - input.Descendants("add").Single().SetAttributeValue("name", "httpplatformhandler"); + input.Descendants("add").Single().SetAttributeValue("name", "aspnetcore"); Assert.True(XNode.DeepEquals(WebConfigTemplate, WebConfigTransform.Transform(input, "test.exe", configureForAzure: false))); } [Fact] - public void WebConfigTransform_does_not_remove_children_of_httpPlatform_element() + public void WebConfigTransform_does_not_remove_children_of_aspNetCore_element() { var envVarElement = new XElement("environmentVariable", new XAttribute("name", "ENVVAR"), new XAttribute("value", "123")); @@ -110,7 +110,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests public void WebConfigTransform_adds_stdoutLogEnabled_if_attribute_is_missing() { var input = WebConfigTemplate; - input.Descendants("httpPlatform").Attributes("stdoutLogEnabled").Remove(); + input.Descendants("aspNetCore").Attributes("stdoutLogEnabled").Remove(); Assert.Equal( "false", @@ -126,11 +126,11 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests { var input = WebConfigTemplate; - var httpPlatformElement = input.Descendants("httpPlatform").Single(); - httpPlatformElement.Attribute("stdoutLogEnabled").Remove(); + var aspNetCoreElement = input.Descendants("aspNetCore").Single(); + aspNetCoreElement.Attribute("stdoutLogEnabled").Remove(); if (stdoutLogFile != null) { - httpPlatformElement.SetAttributeValue("stdoutLogEnabled", stdoutLogFile); + aspNetCoreElement.SetAttributeValue("stdoutLogEnabled", stdoutLogFile); } Assert.Equal( @@ -146,13 +146,13 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests public void WebConfigTransform_does_not_change_existing_stdoutLogEnabled(string stdoutLogEnabledValue) { var input = WebConfigTemplate; - var httpPlatformElement = input.Descendants("httpPlatform").Single(); + var aspNetCoreElement = input.Descendants("aspNetCore").Single(); - httpPlatformElement.SetAttributeValue("stdoutLogFile", "mylog.txt"); - httpPlatformElement.Attributes("stdoutLogEnabled").Remove(); + aspNetCoreElement.SetAttributeValue("stdoutLogFile", "mylog.txt"); + aspNetCoreElement.Attributes("stdoutLogEnabled").Remove(); if (stdoutLogEnabledValue != null) { - input.Descendants("httpPlatform").Single().SetAttributeValue("stdoutLogEnabled", stdoutLogEnabledValue); + input.Descendants("aspNetCore").Single().SetAttributeValue("stdoutLogEnabled", stdoutLogEnabledValue); } Assert.Equal( @@ -165,16 +165,16 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests public void WebConfigTransform_correctly_configures_for_Azure() { var input = WebConfigTemplate; - input.Descendants("httpPlatform").Attributes().Remove(); + input.Descendants("aspNetCore").Attributes().Remove(); - var httPlatformElement = WebConfigTransform.Transform(input, "test.exe", configureForAzure: true) - .Descendants("httpPlatform").Single(); - httPlatformElement.Elements().Remove(); + var aspNetCoreElement = WebConfigTransform.Transform(input, "test.exe", configureForAzure: true) + .Descendants("aspNetCore").Single(); + aspNetCoreElement.Elements().Remove(); Assert.True(XNode.DeepEquals( - XDocument.Parse(@"").Root, - httPlatformElement)); + aspNetCoreElement)); } [Fact] diff --git a/test/Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests/project.json b/test/Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests/project.json index 4a3f14c43f..8a969aebbf 100644 --- a/test/Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests/project.json +++ b/test/Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests/project.json @@ -1,7 +1,7 @@ { "dependencies": { "xunit": "2.1.0", - "dotnet-publish-iis": "1.0.0-*", + "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-*", "Microsoft.NETCore.Platforms": "1.0.1-*" }, "frameworks": {