2015-11-16 11:21:57 -08:00
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
2015-10-06 10:46:43 -07:00
using Microsoft.Dnx.Runtime.Common.CommandLine ;
using Microsoft.DotNet.Cli.Utils ;
2015-11-27 16:19:54 -08:00
using Microsoft.DotNet.ProjectModel ;
2015-12-10 23:00:35 -08:00
using System ;
using System.IO ;
2015-10-06 10:46:43 -07:00
2015-10-07 14:39:36 -07:00
namespace Microsoft.DotNet.Tools.Publish
2015-10-06 10:46:43 -07:00
{
public class Program
{
public static int Main ( string [ ] args )
{
2015-10-13 14:31:29 -07:00
DebugHelper . HandleDebugSwitch ( ref args ) ;
2015-10-06 10:46:43 -07:00
var app = new CommandLineApplication ( ) ;
app . Name = "dotnet publish" ;
app . FullName = ".NET Publisher" ;
app . Description = "Publisher for the .NET Platform" ;
app . HelpOption ( "-h|--help" ) ;
var framework = app . Option ( "-f|--framework <FRAMEWORK>" , "Target framework to compile for" , CommandOptionType . SingleValue ) ;
var runtime = app . Option ( "-r|--runtime <RUNTIME_IDENTIFIER>" , "Target runtime to publish for" , CommandOptionType . SingleValue ) ;
var output = app . Option ( "-o|--output <OUTPUT_PATH>" , "Path in which to publish the app" , CommandOptionType . SingleValue ) ;
2015-10-13 14:31:29 -07:00
var configuration = app . Option ( "-c|--configuration <CONFIGURATION>" , "Configuration under which to build" , CommandOptionType . SingleValue ) ;
2015-12-10 23:00:35 -08:00
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" ) ;
2015-12-21 12:23:05 -08:00
var nativeSubdirectories = app . Option ( "--native-subdirectory" , "Temporary mechanism to include subdirectories from native assets of dependency packages in output" , CommandOptionType . NoValue ) ;
2015-10-06 10:46:43 -07:00
app . OnExecute ( ( ) = >
{
2015-12-10 23:00:35 -08:00
var publish = new PublishCommand ( ) ;
2015-12-02 23:32:27 -08:00
2015-12-10 23:00:35 -08:00
publish . Framework = framework . Value ( ) ;
// TODO: Remove default once xplat publish is enabled.
publish . Runtime = runtime . Value ( ) ? ? RuntimeIdentifier . Current ;
publish . OutputPath = output . Value ( ) ;
publish . Configuration = configuration . Value ( ) ? ? Constants . DefaultConfiguration ;
2015-12-21 12:23:05 -08:00
publish . NativeSubdirectories = nativeSubdirectories . HasValue ( ) ;
2015-11-29 00:14:30 -08:00
2015-12-10 23:00:35 -08:00
publish . ProjectPath = projectPath . Value ;
if ( string . IsNullOrEmpty ( publish . ProjectPath ) )
2015-10-15 12:56:07 -07:00
{
2015-12-10 23:00:35 -08:00
publish . ProjectPath = Directory . GetCurrentDirectory ( ) ;
2015-10-15 12:56:07 -07:00
}
2015-10-06 10:46:43 -07:00
2015-12-10 23:00:35 -08:00
if ( ! publish . TryPrepareForPublish ( ) )
2015-10-06 10:46:43 -07:00
{
2015-11-29 00:14:30 -08:00
return 1 ;
}
2015-12-10 23:00:35 -08:00
publish . PublishAllProjects ( ) ;
Reporter . Output . WriteLine ( $"Published {publish.NumberOfPublishedProjects}/{publish.NumberOfProjects} projects successfully" ) ;
return ( publish . NumberOfPublishedProjects = = publish . NumberOfProjects ) ? 0 : 1 ;
2015-10-06 10:46:43 -07:00
} ) ;
try
{
return app . Execute ( args ) ;
}
2015-10-18 02:06:15 -07:00
catch ( Exception ex )
2015-10-06 10:46:43 -07:00
{
2015-12-10 23:00:35 -08:00
Reporter . Error . WriteLine ( ex . Message . Red ( ) ) ;
Reporter . Verbose . WriteLine ( ex . ToString ( ) . Yellow ( ) ) ;
2015-10-06 10:46:43 -07:00
return 1 ;
}
}
2015-12-21 12:23:05 -08:00
}
2015-10-06 10:46:43 -07:00
}