From 621d8376c3280101e7ef5917d4c380339b27fc8b Mon Sep 17 00:00:00 2001 From: moozzyk Date: Thu, 17 Mar 2016 13:46:46 -0700 Subject: [PATCH] Fixing publish to create executable with the outputName if specified --- .../commands/dotnet-publish/PublishCommand.cs | 12 ++++++---- .../Commands/PublishCommand.cs | 9 +++++--- test/dotnet-publish.Tests/PublishTests.cs | 23 +++++++++++++++++++ 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/dotnet/commands/dotnet-publish/PublishCommand.cs b/src/dotnet/commands/dotnet-publish/PublishCommand.cs index 2c5f3ef29..b1e889962 100644 --- a/src/dotnet/commands/dotnet-publish/PublishCommand.cs +++ b/src/dotnet/commands/dotnet-publish/PublishCommand.cs @@ -193,7 +193,7 @@ namespace Microsoft.DotNet.Tools.Publish if (options.EmitEntryPoint.GetValueOrDefault() && !string.IsNullOrEmpty(context.RuntimeIdentifier)) { Reporter.Verbose.WriteLine($"Copying native host to output to create fully standalone output."); - PublishHost(context, outputPath); + PublishHost(context, outputPath, options); } RunScripts(context, ScriptNames.PostPublish, contextVariables); @@ -223,7 +223,7 @@ namespace Microsoft.DotNet.Tools.Publish } } - private static int PublishHost(ProjectContext context, string outputPath) + private static int PublishHost(ProjectContext context, string outputPath, CommonCompilerOptions compilationOptions) { if (context.TargetFramework.IsDesktop()) { @@ -239,7 +239,9 @@ namespace Microsoft.DotNet.Tools.Publish return 1; } - var outputBinaryName = binaryName.Equals(Constants.HostExecutableName) ? (context.ProjectFile.Name + Constants.ExeSuffix) : binaryName; + var outputBinaryName = binaryName.Equals(Constants.HostExecutableName) + ? ((compilationOptions.OutputName ?? context.ProjectFile.Name) + Constants.ExeSuffix) + : binaryName; var outputBinaryPath = Path.Combine(outputPath, outputBinaryName); File.Copy(hostBinaryPath, outputBinaryPath, overwrite: true); @@ -341,8 +343,8 @@ namespace Microsoft.DotNet.Tools.Publish } // No RID-specific target found, use the RID-less target and publish portable - return allContexts.FirstOrDefault(c => - Equals(c.TargetFramework, f) && + return allContexts.FirstOrDefault(c => + Equals(c.TargetFramework, f) && string.IsNullOrEmpty(c.RuntimeIdentifier)); } diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/PublishCommand.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/PublishCommand.cs index 785a1d386..284d5be39 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/PublishCommand.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/PublishCommand.cs @@ -81,9 +81,12 @@ namespace Microsoft.DotNet.Tools.Test.Utilities public string GetOutputExecutable() { - var result = _project.Name; - result += RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : ""; - return result; + return _project.Name + GetExecutableExtension(); + } + + public string GetExecutableExtension() + { + return RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : ""; } private string BuildArgs() diff --git a/test/dotnet-publish.Tests/PublishTests.cs b/test/dotnet-publish.Tests/PublishTests.cs index 853073aef..2a55c899d 100644 --- a/test/dotnet-publish.Tests/PublishTests.cs +++ b/test/dotnet-publish.Tests/PublishTests.cs @@ -193,5 +193,28 @@ namespace Microsoft.DotNet.Tools.Publish.Tests result.Should().HaveStdOutMatching("\nprepublish_output( \\?[^%]+\\?){5}.+\npostpublish_output( \\?[^%]+\\?){5}", RegexOptions.Singleline); result.Should().Pass(); } + + public void PublishAppWithOutputAssemblyName() + { + TestInstance instance = + TestAssetsManager + .CreateTestInstance("AppWithOutputAssemblyName") + .WithLockFiles() + .WithBuildArtifacts(); + + var testRoot = _getProjectJson(instance.TestRoot, "AppWithOutputAssemblyName"); + var publishCommand = new PublishCommand(testRoot, output: testRoot); + publishCommand.Execute().Should().Pass(); + + var publishedDir = publishCommand.GetOutputDirectory(); + var extension = publishCommand.GetExecutableExtension(); + var outputExe = "MyApp" + extension; + publishedDir.Should().HaveFiles(new[] { "MyApp.dll", outputExe }); + publishedDir.Should().NotHaveFile("AppWithOutputAssemblyName" + extension); + publishedDir.Should().NotHaveFile("AppWithOutputAssemblyName.dll"); + + var command = new TestCommand(Path.Combine(publishedDir.FullName, outputExe)); + command.Execute("").Should().ExitWith(0); + } } }