Fixing publish to create executable with the outputName if specified
This commit is contained in:
parent
03f5379165
commit
621d8376c3
3 changed files with 36 additions and 8 deletions
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue