parent
f58641be49
commit
152c11394e
|
|
@ -61,23 +61,11 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools
|
||||||
// replaced with backwards slashes when the application is published on a non-Windows machine
|
// replaced with backwards slashes when the application is published on a non-Windows machine
|
||||||
var appPath = Path.Combine(".", appName).Replace("/", "\\");
|
var appPath = Path.Combine(".", appName).Replace("/", "\\");
|
||||||
var logPath = Path.Combine(configureForAzure ? @"\\?\%home%\LogFiles" : @".\logs", "stdout").Replace("/", "\\");
|
var logPath = Path.Combine(configureForAzure ? @"\\?\%home%\LogFiles" : @".\logs", "stdout").Replace("/", "\\");
|
||||||
|
RemoveLauncherArgs(aspNetCoreElement);
|
||||||
|
|
||||||
if (!isPortable)
|
if (!isPortable)
|
||||||
{
|
{
|
||||||
aspNetCoreElement.SetAttributeValue("processPath", appPath);
|
aspNetCoreElement.SetAttributeValue("processPath", appPath);
|
||||||
var arguments = (string)aspNetCoreElement.Attribute("arguments");
|
|
||||||
|
|
||||||
if (arguments != null)
|
|
||||||
{
|
|
||||||
const string launcherArgs = "%LAUNCHER_ARGS%";
|
|
||||||
var position = 0;
|
|
||||||
while ((position = arguments.IndexOf(launcherArgs, position, StringComparison.OrdinalIgnoreCase)) >= 0)
|
|
||||||
{
|
|
||||||
arguments = arguments.Remove(position, launcherArgs.Length);
|
|
||||||
}
|
|
||||||
|
|
||||||
aspNetCoreElement.SetAttributeValue("arguments", arguments.Trim());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -85,10 +73,12 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools
|
||||||
|
|
||||||
// In Xml the order of attributes does not matter but it is nice to have
|
// In Xml the order of attributes does not matter but it is nice to have
|
||||||
// the `arguments` attribute next to the `processPath` attribute
|
// the `arguments` attribute next to the `processPath` attribute
|
||||||
aspNetCoreElement.Attribute("arguments")?.Remove();
|
var argumentsAttribute = aspNetCoreElement.Attribute("arguments");
|
||||||
|
argumentsAttribute?.Remove();
|
||||||
var attributes = aspNetCoreElement.Attributes().ToList();
|
var attributes = aspNetCoreElement.Attributes().ToList();
|
||||||
var processPathIndex = attributes.FindIndex(a => a.Name.LocalName == "processPath");
|
var processPathIndex = attributes.FindIndex(a => a.Name.LocalName == "processPath");
|
||||||
attributes.Insert(processPathIndex + 1, new XAttribute("arguments", appPath));
|
attributes.Insert(processPathIndex + 1,
|
||||||
|
new XAttribute("arguments", (appPath + " " + (string)argumentsAttribute).Trim()));
|
||||||
|
|
||||||
aspNetCoreElement.Attributes().Remove();
|
aspNetCoreElement.Attributes().Remove();
|
||||||
aspNetCoreElement.Add(attributes);
|
aspNetCoreElement.Add(attributes);
|
||||||
|
|
@ -113,5 +103,22 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools
|
||||||
{
|
{
|
||||||
element.SetAttributeValue(attributeName, (string)element.Attribute(attributeName) ?? value);
|
element.SetAttributeValue(attributeName, (string)element.Attribute(attributeName) ?? value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void RemoveLauncherArgs(XElement aspNetCoreElement)
|
||||||
|
{
|
||||||
|
var arguments = (string)aspNetCoreElement.Attribute("arguments");
|
||||||
|
|
||||||
|
if (arguments != null)
|
||||||
|
{
|
||||||
|
const string launcherArgs = "%LAUNCHER_ARGS%";
|
||||||
|
var position = 0;
|
||||||
|
while ((position = arguments.IndexOf(launcherArgs, position, StringComparison.OrdinalIgnoreCase)) >= 0)
|
||||||
|
{
|
||||||
|
arguments = arguments.Remove(position, launcherArgs.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
aspNetCoreElement.SetAttributeValue("arguments", arguments.Trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -186,22 +186,6 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests
|
||||||
aspNetCoreElement));
|
aspNetCoreElement));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void WebConfigTransform_overwrites_existing_arguments_attribute_for_portable_apps()
|
|
||||||
{
|
|
||||||
var input = WebConfigTemplate;
|
|
||||||
input.Descendants("aspNetCore").Single().SetAttributeValue("arguments", "42");
|
|
||||||
|
|
||||||
var aspNetCoreElement =
|
|
||||||
WebConfigTransform.Transform(input, "test.exe", configureForAzure: false, isPortable: true)
|
|
||||||
.Descendants("aspNetCore").Single();
|
|
||||||
|
|
||||||
Assert.True(XNode.DeepEquals(
|
|
||||||
XDocument.Parse(@"<aspNetCore processPath=""dotnet"" arguments="".\test.exe"" stdoutLogEnabled=""false""
|
|
||||||
stdoutLogFile="".\logs\stdout"" />").Root,
|
|
||||||
aspNetCoreElement));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("%LAUNCHER_ARGS%", "")]
|
[InlineData("%LAUNCHER_ARGS%", "")]
|
||||||
[InlineData(" %launcher_ARGS%", "")]
|
[InlineData(" %launcher_ARGS%", "")]
|
||||||
|
|
@ -224,6 +208,29 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests
|
||||||
Assert.Equal(outputArguments, (string)aspNetCoreElement.Attribute("arguments"));
|
Assert.Equal(outputArguments, (string)aspNetCoreElement.Attribute("arguments"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("", ".\\myapp.dll")]
|
||||||
|
[InlineData("%LAUNCHER_ARGS%", ".\\myapp.dll")]
|
||||||
|
[InlineData("%LAUNCHER_ARGS% %launcher_args%", ".\\myapp.dll")]
|
||||||
|
[InlineData("-my-switch", ".\\myapp.dll -my-switch")]
|
||||||
|
[InlineData(" %launcher_args% -my-switch", ".\\myapp.dll -my-switch")]
|
||||||
|
[InlineData("-my-switch %LaUnChEr_ArGs%", ".\\myapp.dll -my-switch")]
|
||||||
|
[InlineData("-switch-1 -switch-2", ".\\myapp.dll -switch-1 -switch-2")]
|
||||||
|
[InlineData("-switch-1 %LAUNCHER_ARGS% -switch-2", ".\\myapp.dll -switch-1 -switch-2")]
|
||||||
|
[InlineData("%LAUNCHER_ARGS% -switch %launcher_args%", ".\\myapp.dll -switch")]
|
||||||
|
public void WebConfigTransform_wont_override_existing_args_for_portable_apps(string inputArguments, string outputArguments)
|
||||||
|
{
|
||||||
|
var input = WebConfigTemplate;
|
||||||
|
input.Descendants("aspNetCore").Single().SetAttributeValue("arguments", inputArguments);
|
||||||
|
|
||||||
|
var aspNetCoreElement =
|
||||||
|
WebConfigTransform.Transform(input, "myapp.dll", configureForAzure: false, isPortable: true)
|
||||||
|
.Descendants("aspNetCore").Single();
|
||||||
|
|
||||||
|
Assert.Equal(outputArguments, (string)aspNetCoreElement.Attribute("arguments"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private bool VerifyMissingElementCreated(params string[] elementNames)
|
private bool VerifyMissingElementCreated(params string[] elementNames)
|
||||||
{
|
{
|
||||||
var input = WebConfigTemplate;
|
var input = WebConfigTemplate;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue