protected async Task ExecuteSynchronizeCommand(string manifest) { ServiceCollection services = new ServiceCollection(); services.AddSingleton <SynchronizeCommand>(); Program program = new Program(); program.ConfigureServiceCollection(services); ServiceProvider provider = services.BuildServiceProvider(); GlobalCommand globalCommand = ActivatorUtilities.CreateInstance <GlobalCommand>(provider); CommandOptions commandOptions = provider.GetService <ICommandOptions>() as CommandOptions; commandOptions.RegisterOptions(globalCommand); SynchronizeCommand command = provider.GetRequiredService <SynchronizeCommand>(); CancellationTokenSource cts = new CancellationTokenSource(); string manifestFile = null; try { manifestFile = Path.GetTempFileName(); File.WriteAllText(manifestFile, manifest); command.HandlePositionalArguments(new List <string> { manifestFile }); await command.RunAsync(cts.Token); } finally { if (manifestFile != null) { File.Delete(manifestFile); } } }