From f58641be4977d26a5c83221d4863ec36d4b852da Mon Sep 17 00:00:00 2001 From: moozzyk Date: Thu, 12 May 2016 15:45:49 -0700 Subject: [PATCH] Adding support for outputName build option Addresses #128 --- NuGet.config | 1 + .../Program.cs | 5 +- .../PublishIISCommand.cs | 8 ++- ...re.Server.IISIntegration.Tools.Tests.xproj | 3 ++ .../PublishIISCommandFacts.cs | 52 +++++++++++++++++-- 5 files changed, 60 insertions(+), 9 deletions(-) diff --git a/NuGet.config b/NuGet.config index 5500f6d507..5514866333 100644 --- a/NuGet.config +++ b/NuGet.config @@ -1,6 +1,7 @@  + diff --git a/src/Microsoft.AspNetCore.Server.IISIntegration.Tools/Program.cs b/src/Microsoft.AspNetCore.Server.IISIntegration.Tools/Program.cs index e4312fd81d..f8acff10c0 100644 --- a/src/Microsoft.AspNetCore.Server.IISIntegration.Tools/Program.cs +++ b/src/Microsoft.AspNetCore.Server.IISIntegration.Tools/Program.cs @@ -19,8 +19,9 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools }; app.HelpOption("-h|--help"); - var publishFolderOption = app.Option("--publish-folder|-p", "The path to the publish output folder", CommandOptionType.SingleValue); + var publishFolderOption = app.Option("-p|--publish-folder", "The path to the publish output folder", CommandOptionType.SingleValue); var frameworkOption = app.Option("-f|--framework ", "Target framework of application being published", CommandOptionType.SingleValue); + var configurationOption = app.Option("-c|--configuration ", "Target configuration of application being published", CommandOptionType.SingleValue); var projectPath = app.Argument("", "The path to the project (project folder or project.json) being published. If empty the current directory is used."); app.OnExecute(() => @@ -36,7 +37,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools Reporter.Output.WriteLine($"Configuring the following project for use with IIS: '{publishFolder}'"); - var exitCode = new PublishIISCommand(publishFolder, framework, projectPath.Value).Run(); + var exitCode = new PublishIISCommand(publishFolder, framework, configurationOption.Value(), projectPath.Value).Run(); Reporter.Output.WriteLine("Configuring project completed successfully"); diff --git a/src/Microsoft.AspNetCore.Server.IISIntegration.Tools/PublishIISCommand.cs b/src/Microsoft.AspNetCore.Server.IISIntegration.Tools/PublishIISCommand.cs index 4d776cf357..b57b046821 100644 --- a/src/Microsoft.AspNetCore.Server.IISIntegration.Tools/PublishIISCommand.cs +++ b/src/Microsoft.AspNetCore.Server.IISIntegration.Tools/PublishIISCommand.cs @@ -17,12 +17,14 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools private readonly string _publishFolder; private readonly string _projectPath; private readonly string _framework; + private readonly string _configuration; - public PublishIISCommand(string publishFolder, string framework, string projectPath) + public PublishIISCommand(string publishFolder, string framework, string configuration, string projectPath) { _publishFolder = publishFolder; _projectPath = projectPath; _framework = framework; + _configuration = configuration; } public int Run() @@ -48,7 +50,9 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools var projectContext = GetProjectContext(applicationBasePath, _framework); var isPortable = !projectContext.TargetFramework.IsDesktop() && projectContext.IsPortable; - var applicationName = projectContext.ProjectFile.Name + (isPortable ? ".dll" : ".exe"); + var applicationName = + projectContext.ProjectFile.GetCompilerOptions(projectContext.TargetFramework, _configuration).OutputName + + (isPortable ? ".dll" : ".exe"); var transformedConfig = WebConfigTransform.Transform(webConfigXml, applicationName, ConfigureForAzure(), isPortable); using (var f = new FileStream(webConfigPath, FileMode.Create)) diff --git a/test/Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests/Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests.xproj b/test/Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests/Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests.xproj index 104fc01ce2..4d265e078f 100644 --- a/test/Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests/Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests.xproj +++ b/test/Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests/Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests.xproj @@ -14,5 +14,8 @@ 2.0 + + + \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests/PublishIISCommandFacts.cs b/test/Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests/PublishIISCommandFacts.cs index 3208870b50..5131e7c74f 100644 --- a/test/Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests/PublishIISCommandFacts.cs +++ b/test/Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests/PublishIISCommandFacts.cs @@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests { var folders = CreateTestDir($@"{{ ""frameworks"": {{ ""{targetFramework}"": {{ }} }} }}"); - new PublishIISCommand(folders.PublishOutput, targetFramework, folders.ProjectPath).Run(); + new PublishIISCommand(folders.PublishOutput, targetFramework, null, folders.ProjectPath).Run(); var processPath = (string)GetPublishedWebConfig(folders.PublishOutput) .Descendants("aspNetCore").Attributes("processPath").Single(); @@ -50,7 +50,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests } }"); - new PublishIISCommand(folders.PublishOutput, "netcoreapp1.0", folders.ProjectPath).Run(); + new PublishIISCommand(folders.PublishOutput, "netcoreapp1.0", null, folders.ProjectPath).Run(); var aspNetCoreElement = GetPublishedWebConfig(folders.PublishOutput) .Descendants("aspNetCore").Single(); @@ -68,7 +68,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests { var folders = CreateTestDir($@"{{ ""name"": ""{projectName}"", ""frameworks"": {{ ""netcoreapp1.0"": {{}} }} }}"); - new PublishIISCommand(folders.PublishOutput, "netcoreapp1.0", folders.ProjectPath).Run(); + new PublishIISCommand(folders.PublishOutput, "netcoreapp1.0", null, folders.ProjectPath).Run(); var processPath = (string)GetPublishedWebConfig(folders.PublishOutput) .Descendants("aspNetCore").Attributes("processPath").Single(); @@ -78,6 +78,48 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests Directory.Delete(folders.TestRoot, recursive: true); } + [Fact] + public void PublishIIS_reads_application_name_from_outputName_if_specified() + { + var folders = CreateTestDir( +@"{ + ""name"": ""awesomeApp"", + ""buildOptions"": { ""outputName"": ""myApp"" }, + ""frameworks"": { ""netcoreapp1.0"": { } } +}"); + + new PublishIISCommand(folders.PublishOutput, "netcoreapp1.0", null, folders.ProjectPath).Run(); + + var processPath = (string)GetPublishedWebConfig(folders.PublishOutput) + .Descendants("aspNetCore").Attributes("processPath").Single(); + + Assert.Equal(@".\myApp.exe", processPath); + + Directory.Delete(folders.TestRoot, recursive: true); + } + + [Theory] + [InlineData("Debug", "myApp")] + [InlineData("Release", "awesomeApp")] + public void PublishIIS_reads_application_name_from_configuration_specific_outputName_if_specified(string configuration, string expectedName) + { + var folders = CreateTestDir( +@"{ + ""name"": ""awesomeApp"", + ""configurations"": { ""Debug"": { ""buildOptions"": { ""outputName"": ""myApp"" } } }, + ""frameworks"": { ""netcoreapp1.0"": { } } +}"); + + new PublishIISCommand(folders.PublishOutput, "netcoreapp1.0", configuration, folders.ProjectPath).Run(); + + var processPath = (string)GetPublishedWebConfig(folders.PublishOutput) + .Descendants("aspNetCore").Attributes("processPath").Single(); + + Assert.Equal($@".\{expectedName}.exe", processPath); + + Directory.Delete(folders.TestRoot, recursive: true); + } + [Theory] [InlineData("projectDir")] [InlineData("project.Dir")] @@ -85,7 +127,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests { var folders = CreateTestDir(@"{ ""frameworks"": { ""netcoreapp1.0"": { } } }", projectDir); - new PublishIISCommand(folders.PublishOutput, "netcoreapp1.0", + new PublishIISCommand(folders.PublishOutput, "netcoreapp1.0", null, Path.Combine(folders.ProjectPath, "project.json")).Run(); var processPath = (string)GetPublishedWebConfig(folders.PublishOutput) @@ -111,7 +153,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests "); - new PublishIISCommand(folders.PublishOutput, "netcoreapp1.0", + new PublishIISCommand(folders.PublishOutput, "netcoreapp1.0", null, Path.Combine(folders.ProjectPath, "project.json")).Run(); var aspNetCoreElement = GetPublishedWebConfig(folders.PublishOutput)