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))
|
if (options.EmitEntryPoint.GetValueOrDefault() && !string.IsNullOrEmpty(context.RuntimeIdentifier))
|
||||||
{
|
{
|
||||||
Reporter.Verbose.WriteLine($"Copying native host to output to create fully standalone output.");
|
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);
|
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())
|
if (context.TargetFramework.IsDesktop())
|
||||||
{
|
{
|
||||||
|
@ -239,7 +239,9 @@ namespace Microsoft.DotNet.Tools.Publish
|
||||||
return 1;
|
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);
|
var outputBinaryPath = Path.Combine(outputPath, outputBinaryName);
|
||||||
|
|
||||||
File.Copy(hostBinaryPath, outputBinaryPath, overwrite: true);
|
File.Copy(hostBinaryPath, outputBinaryPath, overwrite: true);
|
||||||
|
|
|
@ -81,9 +81,12 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
||||||
|
|
||||||
public string GetOutputExecutable()
|
public string GetOutputExecutable()
|
||||||
{
|
{
|
||||||
var result = _project.Name;
|
return _project.Name + GetExecutableExtension();
|
||||||
result += RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : "";
|
}
|
||||||
return result;
|
|
||||||
|
public string GetExecutableExtension()
|
||||||
|
{
|
||||||
|
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
private string BuildArgs()
|
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().HaveStdOutMatching("\nprepublish_output( \\?[^%]+\\?){5}.+\npostpublish_output( \\?[^%]+\\?){5}", RegexOptions.Singleline);
|
||||||
result.Should().Pass();
|
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…
Add table
Add a link
Reference in a new issue