Change name of option to --native-subdirectory, Factor for less intrusive changes

This commit is contained in:
Bryan 2015-12-10 11:56:58 -08:00 committed by Bryan Thornbury
parent bcf9392c40
commit 477b8737db

View file

@ -26,7 +26,7 @@ namespace Microsoft.DotNet.Tools.Publish
var output = app.Option("-o|--output <OUTPUT_PATH>", "Path in which to publish the app", CommandOptionType.SingleValue); var output = app.Option("-o|--output <OUTPUT_PATH>", "Path in which to publish the app", CommandOptionType.SingleValue);
var configuration = app.Option("-c|--configuration <CONFIGURATION>", "Configuration under which to build", CommandOptionType.SingleValue); var configuration = app.Option("-c|--configuration <CONFIGURATION>", "Configuration under which to build", CommandOptionType.SingleValue);
var projectPath = app.Argument("<PROJECT>", "The project to publish, defaults to the current directory. Can be a path to a project.json or a project directory"); var projectPath = app.Argument("<PROJECT>", "The project to publish, defaults to the current directory. Can be a path to a project.json or a project directory");
var subdirectories = app.Option("--subdir", "Include Subdirectories in native assets in the output", CommandOptionType.NoValue); var nativeSubdirectories = app.Option("--native-subdirectory", "Include subdirectories from native assets of dependency packages in output", CommandOptionType.NoValue);
app.OnExecute(() => app.OnExecute(() =>
{ {
@ -108,7 +108,7 @@ namespace Microsoft.DotNet.Tools.Publish
/// <param name="outputPath">Location of published files</param> /// <param name="outputPath">Location of published files</param>
/// <param name="configuration">Debug or Release</param> /// <param name="configuration">Debug or Release</param>
/// <returns>Return 0 if successful else return non-zero</returns> /// <returns>Return 0 if successful else return non-zero</returns>
private static int Publish(ProjectContext context, string outputPath, string configuration, bool subdirectories) private static int Publish(ProjectContext context, string outputPath, string configuration, bool nativeSubdirectories)
{ {
Reporter.Output.WriteLine($"Publishing {context.RootProject.Identity.Name.Yellow()} for {context.TargetFramework.DotNetFrameworkName.Yellow()}/{context.RuntimeIdentifier.Yellow()}"); Reporter.Output.WriteLine($"Publishing {context.RootProject.Identity.Name.Yellow()} for {context.TargetFramework.DotNetFrameworkName.Yellow()}/{context.RuntimeIdentifier.Yellow()}");
@ -160,7 +160,7 @@ namespace Microsoft.DotNet.Tools.Publish
Reporter.Verbose.WriteLine($"Publishing {export.Library.Identity.ToString().Green().Bold()} ..."); Reporter.Verbose.WriteLine($"Publishing {export.Library.Identity.ToString().Green().Bold()} ...");
PublishFiles(export.RuntimeAssemblies, outputPath, false); PublishFiles(export.RuntimeAssemblies, outputPath, false);
PublishFiles(export.NativeLibraries, outputPath, subdirectories); PublishFiles(export.NativeLibraries, outputPath, nativeSubdirectories);
} }
// Publish a host if this is an application // Publish a host if this is an application
@ -196,16 +196,11 @@ namespace Microsoft.DotNet.Tools.Publish
return 0; return 0;
} }
private static void PublishFiles(IEnumerable<LibraryAsset> files, string outputPath, bool subdirectories) private static void PublishFiles(IEnumerable<LibraryAsset> files, string outputPath, bool nativeSubdirectories)
{ {
foreach (var file in files) foreach (var file in files)
{ {
var destinationDirectory = outputPath; var destinationDirectory = DetermineFileDestinationDirectory(file, outputPath, nativeSubdirectories);
if (subdirectories)
{
destinationDirectory = Path.Combine(outputPath, GetNativeRelativeSubdirectory(file.RelativePath));
}
if (!Directory.Exists(destinationDirectory)) if (!Directory.Exists(destinationDirectory))
{ {
@ -216,6 +211,18 @@ namespace Microsoft.DotNet.Tools.Publish
} }
} }
private static string DetermineFileDestinationDirectory(LibraryAsset file, string outputPath, bool nativeSubdirectories)
{
var destinationDirectory = outputPath;
if (nativeSubdirectories)
{
destinationDirectory = Path.Combine(outputPath, GetNativeRelativeSubdirectory(file.RelativePath));
}
return destinationDirectory;
}
private static string GetNativeRelativeSubdirectory(string filepath) private static string GetNativeRelativeSubdirectory(string filepath)
{ {
string directoryPath = Path.GetDirectoryName(filepath); string directoryPath = Path.GetDirectoryName(filepath);