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,24 +1,25 @@
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"commands": {
"dotnet": "Microsoft.DotNet.Cli"
},
"dependencies": {
"Microsoft.NETCore.Runtime": "1.0.1-*",
"name": "dotnet",
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"commands": {
"dotnet": "Microsoft.DotNet.Cli"
},
"dependencies": {
"Microsoft.NETCore.Runtime": "1.0.1-*",
"System.Console": "4.0.0-*",
"System.Collections": "4.0.11-*",
"System.Linq": "4.0.1-*",
"System.Diagnostics.Process": "4.1.0-*",
"Microsoft.DotNet.Cli.Utils": {
"type": "build",
"version": "1.0.0-*"
}
},
"frameworks": {
"dnxcore50": { }
"System.Console": "4.0.0-*",
"System.Collections": "4.0.11-*",
"System.Linq": "4.0.1-*",
"System.Diagnostics.Process": "4.1.0-*",
"Microsoft.DotNet.Cli.Utils": {
"type": "build",
"version": "1.0.0-*"
}
},
"frameworks": {
"dnxcore50": { }
}
}

View file

@ -1,32 +1,33 @@
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"commands": {
"dotnet-compile": "Microsoft.DotNet.Tools.Compiler"
},
"dependencies": {
"Microsoft.NETCore.TestHost": "1.0.0-*",
"Microsoft.NETCore.Runtime": "1.0.1-*",
"name": "dotnet-compile",
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"commands": {
"dotnet-compile": "Microsoft.DotNet.Tools.Compiler"
},
"dependencies": {
"Microsoft.NETCore.TestHost": "1.0.0-*",
"Microsoft.NETCore.Runtime": "1.0.1-*",
"System.Console": "4.0.0-*",
"System.Collections": "4.0.11-*",
"System.Linq": "4.0.1-*",
"System.Diagnostics.Process": "4.1.0-*",
"System.IO.FileSystem": "4.0.1-*",
"Microsoft.Extensions.ProjectModel": "1.0.0-*",
"Microsoft.DotNet.Cli.Utils": {
"type": "build",
"version": "1.0.0-*"
},
"Microsoft.Extensions.CommandLineUtils.Sources": {
"type": "build",
"version": "1.0.0-*"
},
"Microsoft.Net.Compilers.netcore": "1.1.0-*"
"System.Console": "4.0.0-*",
"System.Collections": "4.0.11-*",
"System.Linq": "4.0.1-*",
"System.Diagnostics.Process": "4.1.0-*",
"System.IO.FileSystem": "4.0.1-*",
"Microsoft.Extensions.ProjectModel": "1.0.0-*",
"Microsoft.DotNet.Cli.Utils": {
"type": "build",
"version": "1.0.0-*"
},
"frameworks": {
"dnxcore50": { }
}
"Microsoft.Extensions.CommandLineUtils.Sources": {
"type": "build",
"version": "1.0.0-*"
},
"Microsoft.Net.Compilers.netcore": "1.1.0-*"
},
"frameworks": {
"dnxcore50": { }
}
}

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}");
// Hackily generate the output path
// Generate the output path
if (string.IsNullOrEmpty(outputPath))
{
outputPath = Path.Combine(
@ -87,6 +87,7 @@ namespace Microsoft.DotNet.Tools.Publish
context.TargetFramework.GetTwoDigitShortFolderName(),
"publish");
}
if (!Directory.Exists(outputPath))
{
Directory.CreateDirectory(outputPath);
@ -98,6 +99,7 @@ namespace Microsoft.DotNet.Tools.Publish
.ForwardStdOut()
.RunAsync()
.Result;
if (result.ExitCode != 0)
{
Reporter.Error.WriteLine("Compilation failed!".Red().Bold());
@ -106,6 +108,7 @@ namespace Microsoft.DotNet.Tools.Publish
// Use a library exporter to collect publish assets
var exporter = context.CreateExporter(configuration);
foreach (var export in exporter.GetAllExports())
{
Reporter.Output.WriteLine($"Publishing {export.Library.Identity.ToString().Green().Bold()} ...");
@ -137,12 +140,14 @@ namespace Microsoft.DotNet.Tools.Publish
{
hostsPath = AppContext.BaseDirectory;
}
var coreConsole = Path.Combine(hostsPath, Constants.CoreConsoleName);
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());
return 1;
}
var coreRun = Path.Combine(hostsPath, Constants.CoreRunName);
if (!File.Exists(coreRun))
{
@ -158,11 +163,8 @@ namespace Microsoft.DotNet.Tools.Publish
var outputExe = Path.Combine(outputPath, context.ProjectFile.Name);
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
var script = $@"#!/usr/bin/env bash
// Write a script that can be used to launch with CoreRun
var script = $@"#!/usr/bin/env bash
SOURCE=""${{BASH_SOURCE[0]}}""
while [ -h ""$SOURCE"" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR=""$( cd -P ""$( dirname ""$SOURCE"" )"" && pwd )""
@ -171,16 +173,19 @@ while [ -h ""$SOURCE"" ]; do # resolve $SOURCE until the file is no longer a sym
done
DIR=""$( cd -P ""$( dirname ""$SOURCE"" )"" && pwd )""
exec ""$DIR/corerun"" ""$DIR/{context.ProjectFile.Name}.exe"" $*";
outputExe = Path.Combine(outputPath, context.ProjectFile.Commands.Single().Key);
File.WriteAllText(outputExe, script);
Command.Create("chmod", $"a+x {outputExe}")
.ForwardStdOut()
.ForwardStdErr()
.RunAsync()
.Wait();
File.Copy(outputDll, Path.ChangeExtension(outputDll, ".exe"));
File.Delete(outputDll);
}
File.WriteAllText(outputExe, script);
Command.Create("chmod", $"a+x {outputExe}")
.ForwardStdOut()
.ForwardStdErr()
.RunAsync()
.GetAwaiter()
.GetResult();
File.Copy(outputDll, Path.ChangeExtension(outputDll, ".exe"));
File.Delete(outputDll);
return 0;
}
@ -192,12 +197,14 @@ exec ""$DIR/corerun"" ""$DIR/{context.ProjectFile.Name}.exe"" $*";
{
hostsPath = AppContext.BaseDirectory;
}
var coreConsole = Path.Combine(hostsPath, Constants.CoreConsoleName);
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());
return 1;
}
var coreRun = Path.Combine(hostsPath, Constants.CoreRunName);
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");
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;
}

View file

@ -1,30 +1,31 @@
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
"name": "dotnet-publish",
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"commands": {
"dotnet-publish": "Microsoft.DotNet.Tools.Publish"
},
"dependencies": {
"Microsoft.NETCore.Runtime": "1.0.1-*",
"System.Console": "4.0.0-*",
"System.Collections": "4.0.11-*",
"System.Linq": "4.0.1-*",
"System.Diagnostics.Process": "4.1.0-*",
"System.IO.FileSystem": "4.0.1-*",
"Microsoft.Extensions.ProjectModel": "1.0.0-*",
"Microsoft.DotNet.Cli.Utils": {
"type": "build",
"version": "1.0.0-*"
},
"commands": {
"dotnet-publish": "Microsoft.DotNet.Tools.Publish"
"Microsoft.Extensions.CommandLineUtils.Sources": {
"type": "build",
"version": "1.0.0-*"
},
"dependencies": {
"Microsoft.NETCore.Runtime": "1.0.1-*",
"System.Console": "4.0.0-*",
"System.Collections": "4.0.11-*",
"System.Linq": "4.0.1-*",
"System.Diagnostics.Process": "4.1.0-*",
"System.IO.FileSystem": "4.0.1-*",
"Microsoft.Extensions.ProjectModel": "1.0.0-*",
"Microsoft.DotNet.Cli.Utils": {
"type": "build",
"version": "1.0.0-*"
},
"Microsoft.Extensions.CommandLineUtils.Sources": {
"type": "build",
"version": "1.0.0-*"
},
"System.AppContext": "4.0.1-*"
},
"frameworks": {
"dnxcore50": { }
}
"System.AppContext": "4.0.1-*"
},
"frameworks": {
"dnxcore50": { }
}
}

View file

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