public IEnumerable <Expression <Func <Context, bool> > > GetActionsForContext(Context context) { var actions = new List <Expression <Func <Context, bool> > >(); var dotnetCli = new DotnetCli(context.ProjectFileOrFolder, context.IsVerbose, context.MsBuildProperties); var warp = new WarpCli(context.CurrentPlatform, context.IsVerbose); var wasLinkerPackageAdded = false; if (context.ShouldAddLinkerPackage) { wasLinkerPackageAdded = true; actions.Add(ctx => dotnetCli.AddLinkerPackage()); } actions.Add(ctx => dotnetCli.Publish(ctx, new DotnetPublishOptions(context.Rid, context.ShouldNotRootApplicationAssemblies, context.IsNoCrossGen))); actions.Add(ctx => warp.Pack(ctx, new WarpPackOptions(context.OutputPath))); if (wasLinkerPackageAdded) { actions.Add(ctx => dotnetCli.RemoveLinkerPackage()); } return(actions); }
private void OnExecute() { if (File.Exists(ProjectFileOrFolder)) { ProjectFileOrFolder = Path.GetDirectoryName(ProjectFileOrFolder); } Context context = BuildContext(); try { var actions = new List <Expression <Func <Context, bool> > >(); var dotnetCli = new DotnetCli(ProjectFileOrFolder, IsVerbose); var warp = new WarpCli(context.CurrentPlatform, IsVerbose); if (Link != LinkLevel.None) { actions.Add((ctx) => dotnetCli.AddLinkerPackage()); } var isNoRootApplicationAssemblies = Link == LinkLevel.Aggressive; actions.Add((ctx) => dotnetCli.Publish(ctx, new DotnetPublishOptions(Rid, isNoRootApplicationAssemblies, IsNoCrossGen))); actions.Add((ctx) => warp.Pack(ctx, new WarpPackOptions(Output))); if (Link != LinkLevel.None) { actions.Add((ctx) => dotnetCli.RemoveLinkerPackage()); } RunActions(actions, context); } catch (Exception e) { Environment.ExitCode = 1; if (IsVerbose) { throw; } Console.WriteLine(e is DotnetWarpException ? $"Error: {e.Message}." : $"Unhandled error: {e.Message}"); } finally { context.Dispose(); } }