diff --git a/src/Microsoft.AspNetCore.Server.IISIntegration.Tools/WebConfigTransform.cs b/src/Microsoft.AspNetCore.Server.IISIntegration.Tools/WebConfigTransform.cs index 66e0b60f5d..9945650008 100644 --- a/src/Microsoft.AspNetCore.Server.IISIntegration.Tools/WebConfigTransform.cs +++ b/src/Microsoft.AspNetCore.Server.IISIntegration.Tools/WebConfigTransform.cs @@ -65,6 +65,19 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools if (!isPortable) { 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 { diff --git a/test/Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests/WebConfigTransformFacts.cs b/test/Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests/WebConfigTransformFacts.cs index 4ebfef6c34..1351f88fc3 100644 --- a/test/Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests/WebConfigTransformFacts.cs +++ b/test/Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests/WebConfigTransformFacts.cs @@ -202,6 +202,28 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests aspNetCoreElement)); } + [Theory] + [InlineData("%LAUNCHER_ARGS%", "")] + [InlineData(" %launcher_ARGS%", "")] + [InlineData("%LAUNCHER_args% ", "")] + [InlineData("%LAUNCHER_ARGS% %launcher_args%", "")] + [InlineData(" %LAUNCHER_ARGS% %launcher_args% ", "")] + [InlineData(" %launcher_args% -my-switch", "-my-switch")] + [InlineData("-my-switch %LaUnChEr_ArGs%", "-my-switch")] + [InlineData("-switch-1 %LAUNCHER_ARGS% -switch-2", "-switch-1 -switch-2")] + [InlineData("%LAUNCHER_ARGS% -switch %launcher_args%", "-switch")] + public void WebConfigTransform_removes_LAUNCHER_ARGS_from_arguments_for_standalone_apps(string inputArguments, string outputArguments) + { + var input = WebConfigTemplate; + input.Descendants("aspNetCore").Single().SetAttributeValue("arguments", inputArguments); + + var aspNetCoreElement = + WebConfigTransform.Transform(input, "test.exe", configureForAzure: false, isPortable: false) + .Descendants("aspNetCore").Single(); + + Assert.Equal(outputArguments, (string)aspNetCoreElement.Attribute("arguments")); + } + private bool VerifyMissingElementCreated(params string[] elementNames) { var input = WebConfigTemplate;