public NugetService(Solution solution) { //_defaultPackageSource = new PackageSource(NuGetConstants.DefaultFeedUrl); var factory = new PackageRepositoryFactory(); _remoteRepository = factory.CreateRepository(GalleryUrl); _localRepository = factory.CreateRepository(solution.PackagesFolder()); _sourceRepository = new AggregateRepository(new[] { _remoteRepository, _localRepository }); _fileSystem = new PhysicalFileSystem(solution.PackagesFolder()); _pathResolver = new DefaultPackagePathResolver(_fileSystem); _console = new Console(); _packageManager = new PackageManager(_sourceRepository, _pathResolver, _fileSystem, _localRepository){ Logger = _console }; _packages = new Cache<NugetDependency, IPackage>(dep => { Install(dep); return _sourceRepository.FindPackage(dep.Name, dep.Version); }); }
public static int Main(string[] args) { var console = new Common.Console(); var fileSystem = new PhysicalFileSystem(Directory.GetCurrentDirectory()); try { // Remove NuGet.exe.old RemoveOldFile(fileSystem); // Import Dependencies var p = new Program(); p.Initialize(fileSystem, console); // Add commands to the manager foreach (ICommand cmd in p.Commands) { p.Manager.RegisterCommand(cmd); } CommandLineParser parser = new CommandLineParser(p.Manager); // Parse the command ICommand command = parser.ParseCommandLine(args) ?? p.HelpCommand; // Fallback on the help command if we failed to parse a valid command if (!ArgumentCountValid(command)) { // Get the command name and add it to the argument list of the help command string commandName = command.CommandAttribute.CommandName; // Print invalid command then show help console.WriteLine(NuGetResources.InvalidArguments, commandName); p.HelpCommand.ViewHelpForCommand(commandName); } else { command.Execute(); } } catch (AggregateException exception) { if (ExceptionUtility.Unwrap(exception) == exception) { // If the AggregateException contains more than one InnerException, it cannot be unwrapped. In which case, simply print out individual error messages var messages = exception.InnerExceptions.Select(ex => ex.Message) .Distinct(StringComparer.CurrentCulture); console.WriteError(String.Join("\n", messages)); } } catch (Exception e) { console.WriteError(ExceptionUtility.Unwrap(e).Message); return(1); } return(0); }
public static int Main(string[] args) { var console = new Common.Console(); var fileSystem = new PhysicalFileSystem(Directory.GetCurrentDirectory()); try { // Remove NuGet.exe.old RemoveOldFile(fileSystem); // Import Dependencies var p = new Program(); p.Initialize(fileSystem, console); // Add commands to the manager foreach (ICommand cmd in p.Commands) { p.Manager.RegisterCommand(cmd); } CommandLineParser parser = new CommandLineParser(p.Manager); // Parse the command ICommand command = parser.ParseCommandLine(args) ?? p.HelpCommand; // Fallback on the help command if we failed to parse a valid command if (!ArgumentCountValid(command)) { // Get the command name and add it to the argument list of the help command string commandName = command.CommandAttribute.CommandName; // Print invalid command then show help console.WriteLine(NuGetResources.InvalidArguments, commandName); p.HelpCommand.ViewHelpForCommand(commandName); } else { command.Execute(); } } catch (AggregateException exception) { if (ExceptionUtility.Unwrap(exception) == exception) { // If the AggregateException contains more than one InnerException, it cannot be unwrapped. In which case, simply print out individual error messages var messages = exception.InnerExceptions.Select(ex => ex.Message) .Distinct(StringComparer.CurrentCulture); console.WriteError(String.Join("\n", messages)); } } catch (Exception e) { console.WriteError(ExceptionUtility.Unwrap(e).Message); return 1; } return 0; }
public static int Main(string[] args) { var console = new Common.Console(); var fileSystem = new PhysicalFileSystem(Directory.GetCurrentDirectory()); try { // Remove NuGet.exe.old RemoveOldFile(fileSystem); // Import Dependencies var p = new Program(); p.Initialize(fileSystem, console); // Add commands to the manager foreach (ICommand cmd in p.Commands) { p.Manager.RegisterCommand(cmd); } CommandLineParser parser = new CommandLineParser(p.Manager); // Parse the command ICommand command = parser.ParseCommandLine(args) ?? p.HelpCommand; // Fallback on the help command if we failed to parse a valid command if (!ArgumentCountValid(command)) { // Get the command name and add it to the argument list of the help command string commandName = command.CommandAttribute.CommandName; // Print invalid command then show help console.WriteLine(NuGetResources.InvalidArguments, commandName); p.HelpCommand.ViewHelpForCommand(commandName); } else { command.Execute(); } } catch (Exception e) { console.WriteError(ExceptionUtility.Unwrap(e).Message); return 1; } return 0; }
public NugetService(Solution solution, IEnumerable<string> remoteFeeds) { var repoBuilder = new PackageRepositoryBuilder(); _remoteRepository = repoBuilder.BuildRemote(remoteFeeds); _localRepository = repoBuilder.BuildLocal(solution.PackagesFolder()); _sourceRepository = repoBuilder.BuildSource(_remoteRepository, _localRepository); _fileSystem = new PhysicalFileSystem(solution.PackagesFolder()); _pathResolver = new DefaultPackagePathResolver(_fileSystem); _console = new Console(); _packageManager = new PackageManager(_sourceRepository, _pathResolver, _fileSystem, _localRepository){ Logger = _console }; _packages = new Cache<NugetDependency, IPackage>(dep => { Install(dep); return _sourceRepository.FindPackage(dep.Name, new SemanticVersion(dep.Version)); }); }
public static int Main(string[] args) { DebugHelper.WaitForAttach(ref args); // This is to avoid applying weak event pattern usage, which breaks under Mono or restricted environments, e.g. Windows Azure Web Sites. EnvironmentUtility.SetRunningFromCommandLine(); // set output encoding to UTF8 if -utf8 is specified var oldOutputEncoding = System.Console.OutputEncoding; if (args.Any(arg => String.Equals(arg, "-utf8", StringComparison.OrdinalIgnoreCase))) { args = args.Where(arg => !String.Equals(arg, "-utf8", StringComparison.OrdinalIgnoreCase)).ToArray(); SetConsoleOutputEncoding(System.Text.Encoding.UTF8); } var console = new Common.Console(); var fileSystem = new PhysicalFileSystem(Directory.GetCurrentDirectory()); Func <Exception, string> getErrorMessage = e => e.Message; try { // Remove NuGet.exe.old RemoveOldFile(fileSystem); // Import Dependencies var p = new Program(); p.Initialize(fileSystem, console); // Add commands to the manager foreach (ICommand cmd in p.Commands) { p.Manager.RegisterCommand(cmd); } CommandLineParser parser = new CommandLineParser(p.Manager); // Parse the command ICommand command = parser.ParseCommandLine(args) ?? p.HelpCommand; // Fallback on the help command if we failed to parse a valid command if (!ArgumentCountValid(command)) { // Get the command name and add it to the argument list of the help command string commandName = command.CommandAttribute.CommandName; // Print invalid command then show help console.WriteLine(LocalizedResourceManager.GetString("InvalidArguments"), commandName); p.HelpCommand.ViewHelpForCommand(commandName); } else { SetConsoleInteractivity(console, command as Command); // When we're detailed, get the whole exception including the stack // This is useful for debugging errors. if (console.Verbosity == Verbosity.Detailed) { getErrorMessage = e => e.ToString(); } command.Execute(); } } catch (AggregateException exception) { string message; Exception unwrappedEx = ExceptionUtility.Unwrap(exception); if (unwrappedEx == exception) { // If the AggregateException contains more than one InnerException, it cannot be unwrapped. In which case, simply print out individual error messages message = String.Join(Environment.NewLine, exception.InnerExceptions.Select(getErrorMessage).Distinct(StringComparer.CurrentCulture)); } else { message = getErrorMessage(ExceptionUtility.Unwrap(exception)); } console.WriteError(message); return(1); } catch (Exception e) { console.WriteError(getErrorMessage(ExceptionUtility.Unwrap(e))); return(1); } finally { OptimizedZipPackage.PurgeCache(); SetConsoleOutputEncoding(oldOutputEncoding); } return(0); }
public static int Main(string[] args) { DebugHelper.WaitForAttach(ref args); var console = new Common.Console(); var fileSystem = new PhysicalFileSystem(Directory.GetCurrentDirectory()); Func <Exception, string> getErrorMessage = e => e.Message; // When we're detailed, get the whole exception including the stack // This is useful for debugging errors. if (console.Verbosity == Verbosity.Detailed) { getErrorMessage = e => e.ToString(); } try { // Remove NuGet.exe.old RemoveOldFile(fileSystem); // Import Dependencies var p = new Program(); p.Initialize(fileSystem, console); // Add commands to the manager foreach (ICommand cmd in p.Commands) { p.Manager.RegisterCommand(cmd); } CommandLineParser parser = new CommandLineParser(p.Manager); // Parse the command ICommand command = parser.ParseCommandLine(args) ?? p.HelpCommand; // Fallback on the help command if we failed to parse a valid command if (!ArgumentCountValid(command)) { // Get the command name and add it to the argument list of the help command string commandName = command.CommandAttribute.CommandName; // Print invalid command then show help console.WriteLine(NuGetResources.InvalidArguments, commandName); p.HelpCommand.ViewHelpForCommand(commandName); } else { SetConsoleInteractivity(console, command as Command); command.Execute(); } } catch (AggregateException exception) { string message; Exception unwrappedEx = ExceptionUtility.Unwrap(exception); if (unwrappedEx == exception) { // If the AggregateException contains more than one InnerException, it cannot be unwrapped. In which case, simply print out individual error messages message = String.Join(Environment.NewLine, exception.InnerExceptions.Select(getErrorMessage).Distinct(StringComparer.CurrentCulture)); } else { message = getErrorMessage(ExceptionUtility.Unwrap(exception)); } console.WriteError(message); return(1); } catch (Exception e) { console.WriteError(getErrorMessage(ExceptionUtility.Unwrap(e))); return(1); } return(0); }
public API_NuGet SetUp() { NuGet_Program = new Program(); NuGet_Console = new Console(); return this; }
public static int Main(string[] args) { DebugHelper.WaitForAttach(ref args); var console = new Common.Console(); var fileSystem = new PhysicalFileSystem(Directory.GetCurrentDirectory()); Func<Exception, string> getErrorMessage = e => e.Message; // When we're detailed, get the whole exception including the stack // This is useful for debugging errors. if (console.Verbosity == Verbosity.Detailed) { getErrorMessage = e => e.ToString(); } try { // Remove NuGet.exe.old RemoveOldFile(fileSystem); // Import Dependencies var p = new Program(); p.Initialize(fileSystem, console); // Add commands to the manager foreach (ICommand cmd in p.Commands) { p.Manager.RegisterCommand(cmd); } CommandLineParser parser = new CommandLineParser(p.Manager); // Parse the command ICommand command = parser.ParseCommandLine(args) ?? p.HelpCommand; // Fallback on the help command if we failed to parse a valid command if (!ArgumentCountValid(command)) { // Get the command name and add it to the argument list of the help command string commandName = command.CommandAttribute.CommandName; // Print invalid command then show help console.WriteLine(NuGetResources.InvalidArguments, commandName); p.HelpCommand.ViewHelpForCommand(commandName); } else { SetConsoleInteractivity(console, command as Command); command.Execute(); } } catch (AggregateException exception) { string message; Exception unwrappedEx = ExceptionUtility.Unwrap(exception); if (unwrappedEx == exception) { // If the AggregateException contains more than one InnerException, it cannot be unwrapped. In which case, simply print out individual error messages message = String.Join(Environment.NewLine, exception.InnerExceptions.Select(getErrorMessage).Distinct(StringComparer.CurrentCulture)); } else { message = getErrorMessage(ExceptionUtility.Unwrap(exception)); } console.WriteError(message); return 1; } catch (Exception e) { console.WriteError(getErrorMessage(ExceptionUtility.Unwrap(e))); return 1; } return 0; }
public static int Main(string[] args) { DebugHelper.WaitForAttach(ref args); // This is to avoid applying weak event pattern usage, which breaks under Mono or restricted environments, e.g. Windows Azure Web Sites. EnvironmentUtility.SetRunningFromCommandLine(); // set output encoding to UTF8 if -utf8 is specified var oldOutputEncoding = System.Console.OutputEncoding; if (args.Any(arg => String.Equals(arg, "-utf8", StringComparison.OrdinalIgnoreCase))) { args = args.Where(arg => !String.Equals(arg, "-utf8", StringComparison.OrdinalIgnoreCase)).ToArray(); SetConsoleOutputEncoding(System.Text.Encoding.UTF8); } var console = new Common.Console(); var fileSystem = new PhysicalFileSystem(Directory.GetCurrentDirectory()); Func<Exception, string> getErrorMessage = e => e.Message; try { // Remove NuGet.exe.old RemoveOldFile(fileSystem); // Import Dependencies var p = new Program(); p.Initialize(fileSystem, console); // Add commands to the manager foreach (ICommand cmd in p.Commands) { p.Manager.RegisterCommand(cmd); } CommandLineParser parser = new CommandLineParser(p.Manager); // Parse the command ICommand command = parser.ParseCommandLine(args) ?? p.HelpCommand; // Fallback on the help command if we failed to parse a valid command if (!ArgumentCountValid(command)) { // Get the command name and add it to the argument list of the help command string commandName = command.CommandAttribute.CommandName; // Print invalid command then show help console.WriteLine(LocalizedResourceManager.GetString("InvalidArguments"), commandName); p.HelpCommand.ViewHelpForCommand(commandName); } else { SetConsoleInteractivity(console, command as Command); // When we're detailed, get the whole exception including the stack // This is useful for debugging errors. if (console.Verbosity == Verbosity.Detailed) { getErrorMessage = e => e.ToString(); } command.Execute(); } } catch (AggregateException exception) { string message; Exception unwrappedEx = ExceptionUtility.Unwrap(exception); if (unwrappedEx == exception) { // If the AggregateException contains more than one InnerException, it cannot be unwrapped. In which case, simply print out individual error messages message = String.Join(Environment.NewLine, exception.InnerExceptions.Select(getErrorMessage).Distinct(StringComparer.CurrentCulture)); } else { message = getErrorMessage(ExceptionUtility.Unwrap(exception)); } console.WriteError(message); return 1; } catch (Exception e) { console.WriteError(getErrorMessage(ExceptionUtility.Unwrap(e))); return 1; } finally { OptimizedZipPackage.PurgeCache(); SetConsoleOutputEncoding(oldOutputEncoding); } return 0; }