Moving publish-iis from httpPlatformHandler to aspNetCoreModule

This commit is contained in:
moozzyk 2016-03-11 10:03:14 -08:00
parent 5c50ba0898
commit 54bc8022af
6 changed files with 69 additions and 68 deletions

View File

@ -5,9 +5,9 @@ using System;
using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Cli.Utils;
using Microsoft.Extensions.CommandLineUtils; 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) public static int Main(string[] args)
{ {

View File

@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools
public static XDocument Transform(XDocument webConfig, string appName, bool configureForAzure) public static XDocument Transform(XDocument webConfig, string appName, bool configureForAzure)
{ {
const string HandlersElementName = "handlers"; const string HandlersElementName = "handlers";
const string httpPlatformElementName = "httpPlatform"; const string aspNetCoreElementName = "aspNetCore";
webConfig = webConfig == null || webConfig.Root.Name.LocalName != "configuration" webConfig = webConfig == null || webConfig.Root.Name.LocalName != "configuration"
? XDocument.Parse("<configuration />") ? XDocument.Parse("<configuration />")
@ -22,15 +22,15 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools
var webServerSection = GetOrCreateChild(webConfig.Root, "system.webServer"); var webServerSection = GetOrCreateChild(webConfig.Root, "system.webServer");
TransformHandlers(GetOrCreateChild(webServerSection, HandlersElementName)); 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 // make sure that the aspNetCore element is after handlers element
var httpPlatformElement = webServerSection.Element(HandlersElementName) var aspNetCoreElement = webServerSection.Element(HandlersElementName)
.ElementsBeforeSelf(httpPlatformElementName).SingleOrDefault(); .ElementsBeforeSelf(aspNetCoreElementName).SingleOrDefault();
if (httpPlatformElement != null) if (aspNetCoreElement != null)
{ {
httpPlatformElement.Remove(); aspNetCoreElement.Remove();
webServerSection.Element(HandlersElementName).AddAfterSelf(httpPlatformElement); webServerSection.Element(HandlersElementName).AddAfterSelf(aspNetCoreElement);
} }
return webConfig; return webConfig;
@ -38,41 +38,41 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools
private static void TransformHandlers(XElement handlersElement) private static void TransformHandlers(XElement handlersElement)
{ {
var platformHandlerElement = var aspNetCoreElement =
handlersElement.Elements("add") 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"); aspNetCoreElement = new XElement("add");
handlersElement.Add(platformHandlerElement); handlersElement.Add(aspNetCoreElement);
} }
platformHandlerElement.SetAttributeValue("name", "httpPlatformHandler"); aspNetCoreElement.SetAttributeValue("name", "aspNetCore");
SetAttributeValueIfEmpty(platformHandlerElement, "path", "*"); SetAttributeValueIfEmpty(aspNetCoreElement, "path", "*");
SetAttributeValueIfEmpty(platformHandlerElement, "verb", "*"); SetAttributeValueIfEmpty(aspNetCoreElement, "verb", "*");
SetAttributeValueIfEmpty(platformHandlerElement, "modules", "httpPlatformHandler"); SetAttributeValueIfEmpty(aspNetCoreElement, "modules", "AspNetCoreModule");
SetAttributeValueIfEmpty(platformHandlerElement, "resourceType", "Unspecified"); 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 appPath = Path.Combine(configureForAzure ? @"%home%\site" : "..", appName);
var logPath = Path.Combine(configureForAzure ? @"\\?\%home%\LogFiles" : @"..\logs", "stdout.log"); var logPath = Path.Combine(configureForAzure ? @"\\?\%home%\LogFiles" : @"..\logs", "stdout.log");
httpPlatformElement.SetAttributeValue("processPath", appPath); aspNetCoreElement.SetAttributeValue("processPath", appPath);
SetAttributeValueIfEmpty(httpPlatformElement, "stdoutLogEnabled", "false"); SetAttributeValueIfEmpty(aspNetCoreElement, "stdoutLogEnabled", "false");
SetAttributeValueIfEmpty(httpPlatformElement, "stdoutLogFile", logPath); SetAttributeValueIfEmpty(aspNetCoreElement, "stdoutLogFile", logPath);
SetAttributeValueIfEmpty(httpPlatformElement, "startupTimeLimit", "3600"); 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"; const string appBaseKeyName = "ASPNET_APPLICATIONBASE";
var envVariables = GetOrCreateChild(httpPlatformElement, "environmentVariables"); var envVariables = GetOrCreateChild(aspNetCoreElement, "environmentVariables");
var appBaseElement = envVariables.Elements("environmentVariable").SingleOrDefault(e => var appBaseElement = envVariables.Elements("environmentVariable").SingleOrDefault(e =>
string.Equals((string)e.Attribute("name"), appBaseKeyName, StringComparison.CurrentCultureIgnoreCase)); string.Equals((string)e.Attribute("name"), appBaseKeyName, StringComparison.CurrentCultureIgnoreCase));

View File

@ -5,7 +5,8 @@
"warningsAsErrors": true, "warningsAsErrors": true,
"keyFile": "../../tools/Key.snk", "keyFile": "../../tools/Key.snk",
"nowarn": [ "CS1591" ], "nowarn": [ "CS1591" ],
"xmlDoc": true "xmlDoc": true,
"outputName": "dotnet-publish-iis"
}, },
"dependencies": { "dependencies": {

View File

@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests
new PublishIISCommand(folders.PublishOutput, folders.ProjectPath, null).Run(); new PublishIISCommand(folders.PublishOutput, folders.ProjectPath, null).Run();
var processPath = (string)GetPublishedWebConfig(folders.PublishOutput, webRoot) var processPath = (string)GetPublishedWebConfig(folders.PublishOutput, webRoot)
.Descendants("httpPlatform").Attributes("processPath").Single(); .Descendants("aspNetCore").Attributes("processPath").Single();
Assert.Equal($@"..\projectDir.exe", processPath); Assert.Equal($@"..\projectDir.exe", processPath);
@ -42,7 +42,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests
new PublishIISCommand(folders.PublishOutput, folders.ProjectPath, null).Run(); new PublishIISCommand(folders.PublishOutput, folders.ProjectPath, null).Run();
var processPath = (string)GetPublishedWebConfig(folders.PublishOutput, webRoot) var processPath = (string)GetPublishedWebConfig(folders.PublishOutput, webRoot)
.Descendants("httpPlatform").Attributes("processPath").Single(); .Descendants("aspNetCore").Attributes("processPath").Single();
Assert.Equal($@"..\{projectName}.exe", processPath); Assert.Equal($@"..\{projectName}.exe", processPath);
@ -59,7 +59,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests
new PublishIISCommand(folders.PublishOutput, folders.ProjectPath, null).Run(); new PublishIISCommand(folders.PublishOutput, folders.ProjectPath, null).Run();
var processPath = (string)GetPublishedWebConfig(folders.PublishOutput, webRoot) var processPath = (string)GetPublishedWebConfig(folders.PublishOutput, webRoot)
.Descendants("httpPlatform").Attributes("processPath").Single(); .Descendants("aspNetCore").Attributes("processPath").Single();
Assert.Equal(@"..\projectDir.exe", processPath); Assert.Equal(@"..\projectDir.exe", processPath);
@ -76,7 +76,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests
new PublishIISCommand(folders.PublishOutput, folders.ProjectPath, webRoot).Run(); new PublishIISCommand(folders.PublishOutput, folders.ProjectPath, webRoot).Run();
var processPath = (string)GetPublishedWebConfig(folders.PublishOutput, webRoot) var processPath = (string)GetPublishedWebConfig(folders.PublishOutput, webRoot)
.Descendants("httpPlatform").Attributes("processPath").Single(); .Descendants("aspNetCore").Attributes("processPath").Single();
Assert.Equal(@"..\projectDir.exe", processPath); 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(); new PublishIISCommand(folders.PublishOutput, Path.Combine(folders.ProjectPath, "project.json"), null).Run();
var processPath = (string)GetPublishedWebConfig(folders.PublishOutput, webRoot) var processPath = (string)GetPublishedWebConfig(folders.PublishOutput, webRoot)
.Descendants("httpPlatform").Attributes("processPath").Single(); .Descendants("aspNetCore").Attributes("processPath").Single();
Assert.Equal($@"..\{projectDir}.exe", processPath); Assert.Equal($@"..\{projectDir}.exe", processPath);
@ -111,19 +111,19 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests
@"<configuration> @"<configuration>
<system.webServer> <system.webServer>
<handlers> <handlers>
<add name=""httpPlatformHandler"" path=""*"" verb=""*"" modules=""httpPlatformHandler"" resourceType=""Unspecified""/> <add name=""aspNetCore"" path=""*"" verb=""*"" modules=""AspNetCoreModule"" resourceType=""Unspecified""/>
</handlers> </handlers>
<httpPlatform processPath=""%________%"" stdoutLogEnabled=""false"" startupTimeLimit=""1234""/> <aspNetCore processPath=""%________%"" stdoutLogEnabled=""false"" startupTimeLimit=""1234""/>
</system.webServer> </system.webServer>
</configuration>"); </configuration>");
new PublishIISCommand(folders.PublishOutput, Path.Combine(folders.ProjectPath, "project.json"), null).Run(); new PublishIISCommand(folders.PublishOutput, Path.Combine(folders.ProjectPath, "project.json"), null).Run();
var httpPlatformElement = GetPublishedWebConfig(folders.PublishOutput, webRoot) var aspNetCoreElement = GetPublishedWebConfig(folders.PublishOutput, webRoot)
.Descendants("httpPlatform").Single(); .Descendants("aspNetCore").Single();
Assert.Equal(@"..\projectDir.exe", (string)httpPlatformElement.Attribute("processPath")); Assert.Equal(@"..\projectDir.exe", (string)aspNetCoreElement.Attribute("processPath"));
Assert.Equal(@"1234", (string)httpPlatformElement.Attribute("startupTimeLimit")); Assert.Equal(@"1234", (string)aspNetCoreElement.Attribute("startupTimeLimit"));
Directory.Delete(folders.TestRoot, recursive: true); Directory.Delete(folders.TestRoot, recursive: true);
} }

View File

@ -10,13 +10,13 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests
@"<configuration> @"<configuration>
<system.webServer> <system.webServer>
<handlers> <handlers>
<add name=""httpPlatformHandler"" path=""*"" verb=""*"" modules=""httpPlatformHandler"" resourceType=""Unspecified""/> <add name=""aspNetCore"" path=""*"" verb=""*"" modules=""AspNetCoreModule"" resourceType=""Unspecified""/>
</handlers> </handlers>
<httpPlatform processPath=""..\test.exe"" stdoutLogEnabled=""false"" stdoutLogFile=""..\logs\stdout.log"" startupTimeLimit=""3600""> <aspNetCore processPath=""..\test.exe"" stdoutLogEnabled=""false"" stdoutLogFile=""..\logs\stdout.log"" startupTimeLimit=""3600"">
<environmentVariables> <environmentVariables>
<environmentVariable name=""ASPNET_APPLICATIONBASE"" value=""."" /> <environmentVariable name=""ASPNET_APPLICATIONBASE"" value=""."" />
</environmentVariables> </environmentVariables>
</httpPlatform> </aspNetCore>
</system.webServer> </system.webServer>
</configuration>"); </configuration>");
@ -38,10 +38,10 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests
[InlineData(new object[] { new[] { "system.webServer" } })] [InlineData(new object[] { new[] { "system.webServer" } })]
[InlineData(new object[] { new[] { "add" } })] [InlineData(new object[] { new[] { "add" } })]
[InlineData(new object[] { new[] { "handlers" } })] [InlineData(new object[] { new[] { "handlers" } })]
[InlineData(new object[] { new[] { "httpPlatform" } })] [InlineData(new object[] { new[] { "aspNetCore" } })]
[InlineData(new object[] { new[] { "environmentVariables" } })] [InlineData(new object[] { new[] { "environmentVariables" } })]
[InlineData(new object[] { new[] { "environmentVariable" } })] [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) public void WebConfigTransform_adds_missing_elements(string[] elementNames)
{ {
var input = WebConfigTemplate; var input = WebConfigTemplate;
@ -59,10 +59,10 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests
[InlineData("add", "verb", "test")] [InlineData("add", "verb", "test")]
[InlineData("add", "modules", "mods")] [InlineData("add", "modules", "mods")]
[InlineData("add", "resourceType", "Either")] [InlineData("add", "resourceType", "Either")]
[InlineData("httpPlatform", "stdoutLogEnabled", "true")] [InlineData("aspNetCore", "stdoutLogEnabled", "true")]
[InlineData("httpPlatform", "startupTimeLimit", "1200")] [InlineData("aspNetCore", "startupTimeLimit", "1200")]
[InlineData("httpPlatform", "arguments", "arg1")] [InlineData("aspNetCore", "arguments", "arg1")]
[InlineData("httpPlatform", "stdoutLogFile", "logfile.log")] [InlineData("aspNetCore", "stdoutLogFile", "logfile.log")]
public void WebConfigTransform_wont_override_custom_values(string elementName, string attributeName, string attributeValue) public void WebConfigTransform_wont_override_custom_values(string elementName, string attributeName, string attributeValue)
{ {
var input = WebConfigTemplate; var input = WebConfigTemplate;
@ -77,23 +77,23 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests
{ {
var newProcessPath = var newProcessPath =
(string)WebConfigTransform.Transform(WebConfigTemplate, "app.exe", configureForAzure: false) (string)WebConfigTransform.Transform(WebConfigTemplate, "app.exe", configureForAzure: false)
.Descendants("httpPlatform").Single().Attribute("processPath"); .Descendants("aspNetCore").Single().Attribute("processPath");
Assert.Equal(@"..\app.exe", newProcessPath); Assert.Equal(@"..\app.exe", newProcessPath);
} }
[Fact] [Fact]
public void WebConfigTransform_fixes_httpPlatformHandler_casing() public void WebConfigTransform_fixes_aspnetcore_casing()
{ {
var input = WebConfigTemplate; var input = WebConfigTemplate;
input.Descendants("add").Single().SetAttributeValue("name", "httpplatformhandler"); input.Descendants("add").Single().SetAttributeValue("name", "aspnetcore");
Assert.True(XNode.DeepEquals(WebConfigTemplate, Assert.True(XNode.DeepEquals(WebConfigTemplate,
WebConfigTransform.Transform(input, "test.exe", configureForAzure: false))); WebConfigTransform.Transform(input, "test.exe", configureForAzure: false)));
} }
[Fact] [Fact]
public void WebConfigTransform_does_not_remove_children_of_httpPlatform_element() public void WebConfigTransform_does_not_remove_children_of_aspNetCore_element()
{ {
var envVarElement = var envVarElement =
new XElement("environmentVariable", new XAttribute("name", "ENVVAR"), new XAttribute("value", "123")); 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() public void WebConfigTransform_adds_stdoutLogEnabled_if_attribute_is_missing()
{ {
var input = WebConfigTemplate; var input = WebConfigTemplate;
input.Descendants("httpPlatform").Attributes("stdoutLogEnabled").Remove(); input.Descendants("aspNetCore").Attributes("stdoutLogEnabled").Remove();
Assert.Equal( Assert.Equal(
"false", "false",
@ -126,11 +126,11 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests
{ {
var input = WebConfigTemplate; var input = WebConfigTemplate;
var httpPlatformElement = input.Descendants("httpPlatform").Single(); var aspNetCoreElement = input.Descendants("aspNetCore").Single();
httpPlatformElement.Attribute("stdoutLogEnabled").Remove(); aspNetCoreElement.Attribute("stdoutLogEnabled").Remove();
if (stdoutLogFile != null) if (stdoutLogFile != null)
{ {
httpPlatformElement.SetAttributeValue("stdoutLogEnabled", stdoutLogFile); aspNetCoreElement.SetAttributeValue("stdoutLogEnabled", stdoutLogFile);
} }
Assert.Equal( Assert.Equal(
@ -146,13 +146,13 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests
public void WebConfigTransform_does_not_change_existing_stdoutLogEnabled(string stdoutLogEnabledValue) public void WebConfigTransform_does_not_change_existing_stdoutLogEnabled(string stdoutLogEnabledValue)
{ {
var input = WebConfigTemplate; var input = WebConfigTemplate;
var httpPlatformElement = input.Descendants("httpPlatform").Single(); var aspNetCoreElement = input.Descendants("aspNetCore").Single();
httpPlatformElement.SetAttributeValue("stdoutLogFile", "mylog.txt"); aspNetCoreElement.SetAttributeValue("stdoutLogFile", "mylog.txt");
httpPlatformElement.Attributes("stdoutLogEnabled").Remove(); aspNetCoreElement.Attributes("stdoutLogEnabled").Remove();
if (stdoutLogEnabledValue != null) if (stdoutLogEnabledValue != null)
{ {
input.Descendants("httpPlatform").Single().SetAttributeValue("stdoutLogEnabled", stdoutLogEnabledValue); input.Descendants("aspNetCore").Single().SetAttributeValue("stdoutLogEnabled", stdoutLogEnabledValue);
} }
Assert.Equal( Assert.Equal(
@ -165,16 +165,16 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests
public void WebConfigTransform_correctly_configures_for_Azure() public void WebConfigTransform_correctly_configures_for_Azure()
{ {
var input = WebConfigTemplate; var input = WebConfigTemplate;
input.Descendants("httpPlatform").Attributes().Remove(); input.Descendants("aspNetCore").Attributes().Remove();
var httPlatformElement = WebConfigTransform.Transform(input, "test.exe", configureForAzure: true) var aspNetCoreElement = WebConfigTransform.Transform(input, "test.exe", configureForAzure: true)
.Descendants("httpPlatform").Single(); .Descendants("aspNetCore").Single();
httPlatformElement.Elements().Remove(); aspNetCoreElement.Elements().Remove();
Assert.True(XNode.DeepEquals( Assert.True(XNode.DeepEquals(
XDocument.Parse(@"<httpPlatform processPath=""%home%\site\test.exe"" stdoutLogEnabled=""false"" XDocument.Parse(@"<aspNetCore processPath=""%home%\site\test.exe"" stdoutLogEnabled=""false""
stdoutLogFile=""\\?\%home%\LogFiles\stdout.log"" startupTimeLimit=""3600""/>").Root, stdoutLogFile=""\\?\%home%\LogFiles\stdout.log"" startupTimeLimit=""3600""/>").Root,
httPlatformElement)); aspNetCoreElement));
} }
[Fact] [Fact]

View File

@ -1,7 +1,7 @@
{ {
"dependencies": { "dependencies": {
"xunit": "2.1.0", "xunit": "2.1.0",
"dotnet-publish-iis": "1.0.0-*", "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-*",
"Microsoft.NETCore.Platforms": "1.0.1-*" "Microsoft.NETCore.Platforms": "1.0.1-*"
}, },
"frameworks": { "frameworks": {