Changes to publish

- Added ability to rename a project using the name
entry in project.json. Renaming files doesn't work well when debugging
the pdb can't be loaded.
- Removed the logic that looks at commands on publish. The only
thing that matters is the assembly name.
This commit is contained in:
David Fowler 2015-10-18 00:35:56 -07:00
parent 6bb95c4857
commit ee0d2519e6
5 changed files with 101 additions and 107 deletions

View file

@ -1,4 +1,5 @@
{ {
"name": "dotnet",
"version": "1.0.0-*", "version": "1.0.0-*",
"compilationOptions": { "compilationOptions": {
"emitEntryPoint": true "emitEntryPoint": true

View file

@ -1,4 +1,5 @@
{ {
"name": "dotnet-compile",
"version": "1.0.0-*", "version": "1.0.0-*",
"compilationOptions": { "compilationOptions": {
"emitEntryPoint": true "emitEntryPoint": true

View file

@ -77,7 +77,7 @@ namespace Microsoft.DotNet.Tools.Publish
{ {
Reporter.Output.WriteLine($"Publishing {context.RootProject.Identity.Name.Yellow()} for {context.TargetFramework.DotNetFrameworkName.Yellow()}/{context.RuntimeIdentifier}"); Reporter.Output.WriteLine($"Publishing {context.RootProject.Identity.Name.Yellow()} for {context.TargetFramework.DotNetFrameworkName.Yellow()}/{context.RuntimeIdentifier}");
// Hackily generate the output path // Generate the output path
if (string.IsNullOrEmpty(outputPath)) if (string.IsNullOrEmpty(outputPath))
{ {
outputPath = Path.Combine( outputPath = Path.Combine(
@ -87,6 +87,7 @@ namespace Microsoft.DotNet.Tools.Publish
context.TargetFramework.GetTwoDigitShortFolderName(), context.TargetFramework.GetTwoDigitShortFolderName(),
"publish"); "publish");
} }
if (!Directory.Exists(outputPath)) if (!Directory.Exists(outputPath))
{ {
Directory.CreateDirectory(outputPath); Directory.CreateDirectory(outputPath);
@ -98,6 +99,7 @@ namespace Microsoft.DotNet.Tools.Publish
.ForwardStdOut() .ForwardStdOut()
.RunAsync() .RunAsync()
.Result; .Result;
if (result.ExitCode != 0) if (result.ExitCode != 0)
{ {
Reporter.Error.WriteLine("Compilation failed!".Red().Bold()); Reporter.Error.WriteLine("Compilation failed!".Red().Bold());
@ -106,6 +108,7 @@ namespace Microsoft.DotNet.Tools.Publish
// Use a library exporter to collect publish assets // Use a library exporter to collect publish assets
var exporter = context.CreateExporter(configuration); var exporter = context.CreateExporter(configuration);
foreach (var export in exporter.GetAllExports()) foreach (var export in exporter.GetAllExports())
{ {
Reporter.Output.WriteLine($"Publishing {export.Library.Identity.ToString().Green().Bold()} ..."); Reporter.Output.WriteLine($"Publishing {export.Library.Identity.ToString().Green().Bold()} ...");
@ -137,12 +140,14 @@ namespace Microsoft.DotNet.Tools.Publish
{ {
hostsPath = AppContext.BaseDirectory; hostsPath = AppContext.BaseDirectory;
} }
var coreConsole = Path.Combine(hostsPath, Constants.CoreConsoleName); var coreConsole = Path.Combine(hostsPath, Constants.CoreConsoleName);
if (!File.Exists(coreConsole)) if (!File.Exists(coreConsole))
{ {
Reporter.Error.WriteLine($"Unable to locate {Constants.CoreConsoleName} in {coreConsole}, use {Constants.HostsPathEnvironmentVariable} to set the path to it.".Red().Bold()); Reporter.Error.WriteLine($"Unable to locate {Constants.CoreConsoleName} in {coreConsole}, use {Constants.HostsPathEnvironmentVariable} to set the path to it.".Red().Bold());
return 1; return 1;
} }
var coreRun = Path.Combine(hostsPath, Constants.CoreRunName); var coreRun = Path.Combine(hostsPath, Constants.CoreRunName);
if (!File.Exists(coreRun)) if (!File.Exists(coreRun))
{ {
@ -158,9 +163,6 @@ namespace Microsoft.DotNet.Tools.Publish
var outputExe = Path.Combine(outputPath, context.ProjectFile.Name); var outputExe = Path.Combine(outputPath, context.ProjectFile.Name);
var outputDll = Path.Combine(outputPath, context.ProjectFile.Name + ".dll"); var outputDll = Path.Combine(outputPath, context.ProjectFile.Name + ".dll");
// Check if the a command name is specified, and rename the necessary files
if (context.ProjectFile.Commands.Count == 1)
{
// Write a script that can be used to launch with CoreRun // Write a script that can be used to launch with CoreRun
var script = $@"#!/usr/bin/env bash var script = $@"#!/usr/bin/env bash
SOURCE=""${{BASH_SOURCE[0]}}"" SOURCE=""${{BASH_SOURCE[0]}}""
@ -171,16 +173,19 @@ while [ -h ""$SOURCE"" ]; do # resolve $SOURCE until the file is no longer a sym
done done
DIR=""$( cd -P ""$( dirname ""$SOURCE"" )"" && pwd )"" DIR=""$( cd -P ""$( dirname ""$SOURCE"" )"" && pwd )""
exec ""$DIR/corerun"" ""$DIR/{context.ProjectFile.Name}.exe"" $*"; exec ""$DIR/corerun"" ""$DIR/{context.ProjectFile.Name}.exe"" $*";
outputExe = Path.Combine(outputPath, context.ProjectFile.Commands.Single().Key);
File.WriteAllText(outputExe, script); File.WriteAllText(outputExe, script);
Command.Create("chmod", $"a+x {outputExe}") Command.Create("chmod", $"a+x {outputExe}")
.ForwardStdOut() .ForwardStdOut()
.ForwardStdErr() .ForwardStdErr()
.RunAsync() .RunAsync()
.Wait(); .GetAwaiter()
.GetResult();
File.Copy(outputDll, Path.ChangeExtension(outputDll, ".exe")); File.Copy(outputDll, Path.ChangeExtension(outputDll, ".exe"));
File.Delete(outputDll); File.Delete(outputDll);
}
return 0; return 0;
} }
@ -192,12 +197,14 @@ exec ""$DIR/corerun"" ""$DIR/{context.ProjectFile.Name}.exe"" $*";
{ {
hostsPath = AppContext.BaseDirectory; hostsPath = AppContext.BaseDirectory;
} }
var coreConsole = Path.Combine(hostsPath, Constants.CoreConsoleName); var coreConsole = Path.Combine(hostsPath, Constants.CoreConsoleName);
if (!File.Exists(coreConsole)) if (!File.Exists(coreConsole))
{ {
Reporter.Error.WriteLine($"Unable to locate {Constants.CoreConsoleName} in {coreConsole}, use {Constants.HostsPathEnvironmentVariable} to set the path to it.".Red().Bold()); Reporter.Error.WriteLine($"Unable to locate {Constants.CoreConsoleName} in {coreConsole}, use {Constants.HostsPathEnvironmentVariable} to set the path to it.".Red().Bold());
return 1; return 1;
} }
var coreRun = Path.Combine(hostsPath, Constants.CoreRunName); var coreRun = Path.Combine(hostsPath, Constants.CoreRunName);
if (!File.Exists(coreRun)) if (!File.Exists(coreRun))
{ {
@ -214,22 +221,6 @@ exec ""$DIR/corerun"" ""$DIR/{context.ProjectFile.Name}.exe"" $*";
var outputDll = Path.Combine(outputPath, context.ProjectFile.Name + ".dll"); var outputDll = Path.Combine(outputPath, context.ProjectFile.Name + ".dll");
File.Copy(coreConsole, outputExe, overwrite: true); File.Copy(coreConsole, outputExe, overwrite: true);
// Check if the a command name is specified, and rename the necessary files
if (context.ProjectFile.Commands.Count == 1)
{
var commandName = context.ProjectFile.Commands.Single().Key;
// Move coreconsole and the matching dll
var renamedExe = Path.Combine(outputPath, commandName + ".exe");
var renamedDll = Path.ChangeExtension(renamedExe, ".dll");
if (File.Exists(renamedExe))
{
File.Delete(renamedExe);
}
File.Move(outputExe, renamedExe);
File.Move(outputDll, renamedDll);
outputExe = Path.Combine(outputPath, commandName + ".exe");
}
return 0; return 0;
} }

View file

@ -1,4 +1,5 @@
{ {
"name": "dotnet-publish",
"version": "1.0.0-*", "version": "1.0.0-*",
"compilationOptions": { "compilationOptions": {
"emitEntryPoint": true "emitEntryPoint": true

View file

@ -89,7 +89,7 @@ namespace Microsoft.Extensions.ProjectModel
} }
// Meta-data properties // Meta-data properties
project.Name = projectName; project.Name = rawProject.ValueAsString("name") ?? projectName;
project.ProjectFilePath = Path.GetFullPath(projectPath); project.ProjectFilePath = Path.GetFullPath(projectPath);
var version = rawProject.Value("version") as JsonString; var version = rawProject.Value("version") as JsonString;