Moving publish-iis from httpPlatformHandler to aspNetCoreModule
This commit is contained in:
parent
5c50ba0898
commit
54bc8022af
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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("<configuration />")
|
||||
|
|
@ -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));
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,8 @@
|
|||
"warningsAsErrors": true,
|
||||
"keyFile": "../../tools/Key.snk",
|
||||
"nowarn": [ "CS1591" ],
|
||||
"xmlDoc": true
|
||||
"xmlDoc": true,
|
||||
"outputName": "dotnet-publish-iis"
|
||||
},
|
||||
|
||||
"dependencies": {
|
||||
|
|
|
|||
|
|
@ -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
|
|||
@"<configuration>
|
||||
<system.webServer>
|
||||
<handlers>
|
||||
<add name=""httpPlatformHandler"" path=""*"" verb=""*"" modules=""httpPlatformHandler"" resourceType=""Unspecified""/>
|
||||
<add name=""aspNetCore"" path=""*"" verb=""*"" modules=""AspNetCoreModule"" resourceType=""Unspecified""/>
|
||||
</handlers>
|
||||
<httpPlatform processPath=""%________%"" stdoutLogEnabled=""false"" startupTimeLimit=""1234""/>
|
||||
<aspNetCore processPath=""%________%"" stdoutLogEnabled=""false"" startupTimeLimit=""1234""/>
|
||||
</system.webServer>
|
||||
</configuration>");
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,13 +10,13 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests
|
|||
@"<configuration>
|
||||
<system.webServer>
|
||||
<handlers>
|
||||
<add name=""httpPlatformHandler"" path=""*"" verb=""*"" modules=""httpPlatformHandler"" resourceType=""Unspecified""/>
|
||||
<add name=""aspNetCore"" path=""*"" verb=""*"" modules=""AspNetCoreModule"" resourceType=""Unspecified""/>
|
||||
</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>
|
||||
<environmentVariable name=""ASPNET_APPLICATIONBASE"" value=""."" />
|
||||
</environmentVariables>
|
||||
</httpPlatform>
|
||||
</aspNetCore>
|
||||
</system.webServer>
|
||||
</configuration>");
|
||||
|
||||
|
|
@ -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(@"<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,
|
||||
httPlatformElement));
|
||||
aspNetCoreElement));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
|
|
@ -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": {
|
||||
|
|
|
|||
Loading…
Reference in New Issue